-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
rain.py
75 lines (53 loc) · 2.11 KB
/
rain.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
70
71
72
73
74
75
#!/usr/bin/env python3
from configs import API_URL, REPO_ADDR, REPO_NAME
import requests
import re
import os
import subprocess
def basher(**kwargs) -> None:
""" set the the environment variable with passed arg.name to arg.value and then run the main.sh
:param kwargs: key pair of environment variables
:return: None
"""
for i in kwargs:
os.environ.setdefault(i, kwargs[i])
subprocess.run('./main.sh')
def getIssueContext(response: dict) -> dict:
"""
this function will get a dict which contain an issue and then return a context of its body, title and attachment_link.
:param response:
:return: dict
"""
x = dict(title=None, body=None, attachment_link=None)
x['title'] = response.get('title')
x['body'] = response.get('body')
if x['body']:
if(match := re.findall('(https.*md)', x['body'])):
x['attachment_link'] = match[0]
return x
def downloadAttachment(data: dict, name: str, dest: str, body: bool=False) -> bool:
""" download the attachment url ans save it under ./content/{dest}/{name}/{name}.md
:param url: attachment url
:param name: name to save file as
:return: true if download and save file, false otherwise
"""
if not body:
data = requests.get(data.attachment_link)
while data.status_code != 200:
downloadAttachment(data.attachment_link)
os.mkdir(f'./content/{dest}/{name}')
with open(f'./content/{dest}/{name}/{name}.md', 'wb') as fli:
fli.write(bytes(data['body'], encoding='utf-8')) if body else fli.write(data.content)
return True
return False
res = requests.get(API_URL)
while res.status_code != 200:
res = requests.get(API_URL)
for issue in res.json():
if issue.get('state') == 'open':
if(labels := issue.get('labels')):
for label in labels:
if label.get('name') in ['tools', 'fundamentals']:
x = getIssueContext(issue)
if downloadAttachment(data=x, name=x.get('title'), dest=label.get('name'), body=True):
print('found and downloaded')