Created
October 22, 2014 12:07
-
-
Save lepinkainen/7f2449e083fce5d4359c to your computer and use it in GitHub Desktop.
Hilma to RSS feed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from bs4 import BeautifulSoup | |
| import urllib3 | |
| import json | |
| from datetime import datetime | |
| import PyRSS2Gen | |
| url = "http://www.hankintailmoitukset.fi/fi/notice/search/?_s%5B_sent%5D=1&_s%5Bphrase%5D=&_s%5Bcpv%5D=72-5&_s%5Borganisation%5D=&_s%5Bnuts%5D=&_s%5Bpublished_start%5D=&_s%5Bpublished_end%5D=&_s%5Bform_number%5D%5B%5D=domestic_contract&_s%5Bform_number%5D%5B%5D=contract&_s%5Bform_number%5D%5B%5D=contract_utilities" | |
| http = urllib3.PoolManager() | |
| r = http.request('GET', url) | |
| soup = BeautifulSoup(r.data) | |
| data = soup.table.tbody.findAll("tr") | |
| items=[] | |
| items = [] | |
| for tr in data: | |
| adata = tr.findAll("td") | |
| ''' JSON type reservation ''' | |
| # a = {"published": adata[1].text, "deadline": adata[2].text, "name": adata[3].a.text, "url": adata[3].a['href']} | |
| r = http.request('GET', adata[3].a['href']) | |
| asoup = BeautifulSoup(r.data) | |
| contact = asoup.find_all("table", class_="CONTACT") | |
| try: | |
| contactname = contact[0].tr.find_all("td")[1].text | |
| except: | |
| contactname = "None" | |
| item = PyRSS2Gen.RSSItem( | |
| title = contactname + " - " + adata[3].a.text, | |
| link = adata[3].a['href'], | |
| description = adata[3].a.text + " Deadline: " + adata[2].text, | |
| guid = PyRSS2Gen.Guid(adata[3].a['href']), | |
| pubDate = datetime.strptime(adata[1].text, '%d.%m.%Y %H.%M') | |
| ) | |
| items.append(item) | |
| rss = PyRSS2Gen.RSS2( | |
| title = "HILMA HANKKEET", | |
| link = url, | |
| description = "Stonecrew Hilma prospects", | |
| lastBuildDate = datetime.now(), | |
| items=items | |
| ) | |
| rss.write_xml(open("/var/www/hilmaparser/pyrss2gen.xml", "w"), encoding="utf-8") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment