-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitfitiAnimation.py
52 lines (41 loc) · 2.38 KB
/
GitfitiAnimation.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
import requests
from time import sleep
from subprocess import run, DEVNULL
from glob import glob
from datetime import datetime
from threading import Thread
# TODO imporve framerate
if '-t' not in argv or len(argv) < argv.index('-t'):
print('Missing Token (-t TOKEN)')
exit()
TOKEN = argv[argv.index('-t') + 1]
USERNAME = 'ilarramendi'
REPO_PREFIX = 'DUMMY_'
frames = list(enumerate(sorted(glob('frames/frame-*.json'))))
print(datetime.now().strftime("[%d/%m/%Y %H:%M:%S] =>"), 'Deleting all "' + REPO_PREFIX + '*" repositories')
for i, frame in frames: requests.delete('https://api.github.com/repos/' + USERNAME + '/' + REPO_PREFIX + str(i), headers={'Authorization': 'TOKEN ' + TOKEN})
def deleteRepo(seconds, number):
sleep(seconds)
deleteUrl = 'https://api.github.com/repos/' + USERNAME + '/' + REPO_PREFIX + str(number)
if requests.delete(deleteUrl, headers={'Authorization': 'TOKEN ' + TOKEN}).status_code != 204: print(datetime.now().strftime("[%d/%m/%Y %H:%M:%S] =>"), 'Error deleting repo number:', number)
else: print(datetime.now().strftime("[%d/%m/%Y %H:%M:%S] =>"), 'Deleted previous frame: ', number)
while (True):
for i, frame in frames:
print(datetime.now().strftime("[%d/%m/%Y %H:%M:%S] =>"), 'Drawing frame: ', i)
DATA = {
'name': REPO_PREFIX + str(i),
'description': "Dummy repository for ilarramendi/Gitfiti",
'homepage': 'https://github.com',
'private': False
}
r = requests.post('https://api.github.com/user/repos', json=DATA, headers={'Authorization': 'TOKEN ' + TOKEN})
if r.status_code == 201:
if run(['python3', 'Gitfiti.py', '-u', USERNAME, '-rn', DATA['name'], '-t', TOKEN, '-c', '50', '-i', frame]).returncode == 0:
run(['sh', 'Gitfiti.sh'], stdout=DEVNULL, stderr=DEVNULL)
Thread(target=deleteRepo, args=(120, (i - 1) if i > 0 else (len(frames) - 1))).start()
print(datetime.now().strftime("[%d/%m/%Y %H:%M:%S] =>"),'Waiting to draw next frame')
sleep(30)
else: print(datetime.now().strftime("[%d/%m/%Y %H:%M:%S] =>"), 'Error generating script with Gitfiti.py')
else: print(datetime.now().strftime("[%d/%m/%Y %H:%M:%S] =>"), 'Error creating repo: ', r.content, r.status_code)
print(datetime.now().strftime("[%d/%m/%Y %H:%M:%S] =>"), 'Deleting all "' + REPO_PREFIX + '*" repositories')
for i, frame in frames: requests.delete('https://api.github.com/repos/' + USERNAME + '/' + REPO_PREFIX + str(i), headers={'Authorization': 'TOKEN ' + TOKEN})