-
Notifications
You must be signed in to change notification settings - Fork 0
/
whoisd.py
69 lines (53 loc) · 1.58 KB
/
whoisd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# WHOISD: who is data
import base64
import github3
from rich import print as rprint
import time
def github_connect():
'''
Connect to the github client and correct repository
'''
with open("./mytoken.txt") as f:
token = f.read()
user = "vanHooijdonkC"
sess = github3.login(token=token)
return sess.repository(user, "EH8")
def get_file_contents(file, repo):
'''
returns all the files in the given repository
'''
b64_data = repo.file_contents("data/" + file).content
data = base64.b64decode(b64_data)
datadata = base64.b64decode(data)
return datadata
def prettyprint(filecontents):
'''
Pretty print all the contents of the files with library rich
'''
for x in filecontents:
if filecontents.index(x) % 2 == 0:
rprint(f"\tcontents of file [bold red]{x}[/bold red]:")
else:
try:
rprint(f"{x}\n")
time.sleep(2)
except:
print("this file contains a photo! \n")
def main():
contents = []
try:
print("[*] Attempting to retrieve the data")
repo = github_connect()
dirContent = repo.directory_contents("data/")
if dirContent is not None:
for x in dirContent:
contents.append(x[0])
contents.append(get_file_contents(x[0], repo))
else:
print("try again, no data found yet")
except Exception as e:
print(e)
print("[x] Failed import of the data")
prettyprint(contents)
if __name__ == "__main__":
main()