-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrappi.py
More file actions
62 lines (55 loc) · 2.08 KB
/
Copy pathscrappi.py
File metadata and controls
62 lines (55 loc) · 2.08 KB
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
import requests
import dateparser
from settings import *
G_BLOGURL = "http://firebirds1915.blogspot.com/feeds/posts/default?alt=json"
T_BLOGURL = "http://team1915.blogspot.com/feeds/posts/default?alt=json"
POST_DIR = "_posts/"
def updateChanges(field, time):
"""Updates the settings file with the latest dates for an update blog pull."""
LAST_UPDATED[field] = time
updates = open('settings.py','w')
updates.write("LAST_UPDATED = %s" % LAST_UPDATED)
updates.close()
def writePostEntry(entry):
""" Writes each blog entry to posts"""
d = dateparser.parse(u'%s' % entry['updated']['$t'])
datedfile = str(d.year) + "-" + str(d.month) + "-" + str(d.day) + "-" + entry['title']['$t'].strip().replace(" ", "-").replace("|", "-")
path = POST_DIR + datedfile + '.html'
post = open(path,'w')
post.write("---\n")
post.write("layout: post\n")
post.write("title: \"%s\"\n" % entry['title']['$t'])
post.write("---\n")
post.write(entry['content']['$t'].encode("utf8"))
#dateparser.parse(u'2015-09-17T04:05:53.528-04:00')
#print(data['feed']['updated']['$t'])
#entry['updated']
#entry['published']
post.close()
def updateGroveBog():
"""Retrieves and updates blogs from Mr, Grove's blogger"""
data = requests.get(G_BLOGURL).json()
if data['feed']['updated']['$t'] == LAST_UPDATED['grove']:
print("Mr. Grove's blog is upto date.")
else:
print("updating Mr. Grove's Blog")
for entry in data['feed']['entry']:
writePostEntry(entry)
print("Finished updates.\n Now updating settings.py")
updateChanges('grove', data['feed']['updated']['$t'])
def updateTeamBog():
""" Pulls entries from the team blogger and posts them to posts"""
data = requests.get(T_BLOGURL).json()
if data['feed']['updated']['$t'] == LAST_UPDATED['team']:
print("The Team Blog is upto date.")
else:
print("updating The Team Blog")
for entry in data['feed']['entry']:
writePostEntry(entry)
print("Finished updates.\n Now updating settings.py")
updateChanges('team', data['feed']['updated']['$t'])
def main():
""" Checks for blogs to be updated and pulls latest entries to posts"""
updateGroveBog()
updateTeamBog()
main()