-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaucy.py
78 lines (57 loc) · 2.08 KB
/
saucy.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
76
77
78
import feedparser
import re
import requests
import string
import sys
import os
import github3
link = ""
owner = os.environ['GITHUB_ACTOR']
owner = 'botonomi'
xml = open("feed.xml", "w")
feed = 'https://github.com/ripienaar/free-for-dev/commits/master.atom'
raw = feedparser.parse(feed)
xml.write('<?xml version="1.0" encoding="UTF-8" ?>')
xml.write("\n")
xml.write('<rss version="2.0">')
xml.write('<channel>\n<title>New Free-For-Dev</title>\n<description>New Free Resources</description>\n<link>')
xml.write(link)
xml.write("</link>\n")
for entry in raw.entries:
if not re.search('Merge\Wpull\Wrequest', entry.title):
xml.write("<item>\n\t<title>")
xml.write(entry.title)
xml.write("</title>\n\t<link>")
xml.write(entry.link)
xml.write('</link><description><![CDATA[')
patch = requests.get(entry.link + '.patch', verify=False)
for line in patch.text.split("\n"):
try:
lead = list(line)[0]
if list(line)[0] == "+" and list(line)[1] != "+":
line = line[1:]
w = re.search("\[(.*)\]\((.*)\)", line)
name = w.group(1)
url = w.group(2)
#if 'http' not in url:
# url = 'https://' + url
desclink = '<a href="' + url + '">' + url + '</a>'
desctext = ' '.join(line.split()[3:])
xml.write(desclink)
xml.write(" - ")
xml.write(desctext)
xml.write("<br>\n")
except Exception:
continue
xml.write(' ]]></description>')
xml.write("\n</item>\n")
xml.write("\n</channel>\n</rss>\n")
xml.close()
# Connect to GitHub API and push the changes.
github = github3.login(token=os.environ['TOKEN'])
repository = github.repository(owner, 'awesomesauce')
with open('feed.xml', 'rb') as fd:
contents = fd.read()
contents_object = repository.file_contents('feed.xml')
push_status = contents_object.update('automatic', contents)
print(push_status)