-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss.py
55 lines (44 loc) · 1.82 KB
/
rss.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
import os
import datetime
import PyRSS2Gen
from ftplib import FTP
import config
def create_feed():
#set date for RSS lastBuildDate variable
lastModified = os.path.getmtime('bills_output.txt')
lastModifiedDatetime = datetime.datetime.fromtimestamp(lastModified)
print "Assigning last modified date as: {0}".format(lastModifiedDatetime)
#open and read the txt file; add each line to a list object
bills_list = open('bills_output.txt').read().splitlines()
bill_items = []
#split each Bill string into parts and create PyRSS2Gem RSSItem objects from
#them
for bill in bills_list:
#Extract relevant bits of each Bill string
date = bill[:bill.find(':')]
bill_url = bill[bill.find('http'):]
bill_title = bill[bill.find(':')+2:bill.find('http')-2]
#convert extracts into RRS items
item = PyRSS2Gen.RSSItem(title = bill_title,
link = bill_url,
description = bill_title + " - bill homepage updated " + date,
pubDate = date)
#Append all items to a list
bill_items.append(item)
#List needs to be reversed to get newest Bills to the top
bill_items.reverse()
#Create the RSS feed and write it to file
rss = PyRSS2Gen.RSS2(title = "Richard's APH Bills RSS",
link = "https://github.com/richyvk/APH-RSS",
description = "An RSS feed of Bill updates from the APH homepage",
lastBuildDate = lastModifiedDatetime,
items = bill_items)
rss.write_xml(open("feed.xml", "w"))
def ftp_feed():
#establish ftp connection and login
ftp = FTP(config.ftp_url)
ftp.login(config.ftp_username,config.ftp_password)
ftp.cwd(config.ftp_target)
ftp.storbinary('STOR '+'feed.xml', open('feed.xml', 'rb'))
print "File FTPed successfully"
ftp.quit()