SHOW:
|
|
- or go back to the newest paste.
| 1 | import feedparser | |
| 2 | - | import requests as req |
| 2 | + | |
| 3 | import hashlib | |
| 4 | - | re_coin_link = re.compile(r'(http\S+coins?.htm)', re.DOTALL) |
| 4 | + | |
| 5 | ||
| 6 | - | rss_url = 'http://www.cbr.ru/rss/RssPress' |
| 6 | + | url = "http://www.cbr.ru/rss/RssPress" |
| 7 | - | resp_rss = req.get(rss_url) |
| 7 | + | rss = feedparser.parse(url) |
| 8 | - | press_relise_coin_url = re_coin_link.findall(resp_rss.text) |
| 8 | + | |
| 9 | - | dates = [] |
| 9 | + | i_title = [] |
| 10 | last_hash = [] | |
| 11 | - | for i in press_relise_coin_url: |
| 11 | + | j_href = [] |
| 12 | - | resp_html_press_relise = req.get(i) |
| 12 | + | reg = re.compile(r'памятн', re.DOTALL) |
| 13 | - | html_press_relise = resp_html_press_relise.text |
| 13 | + | |
| 14 | - | clear_html_press_relise = re.sub(r' |«|»', ' ', html_press_relise,flags = re.DOTALL) |
| 14 | + | for i in rss.entries: |
| 15 | # print(i) | |
| 16 | - | re_date = re.compile(r'Банк России\s(\d*)\s([а-яА-Я]*)\s(\d*).*выпускает в обращение', re.DOTALL) |
| 16 | + | if reg.findall(i.title): |
| 17 | - | get_date = re_date.findall(clear_html_press_relise) |
| 17 | + | # print(i) |
| 18 | - | # print(get_date) |
| 18 | + | i_title.append(i.title) |
| 19 | j_href.append(i.link) | |
| 20 | - | dates.append(list({"date": x[0], 'month': x[1], "year": x[2]} for x in get_date))
|
| 20 | + | last_hash = hashlib.md5(rss.entries[0].title + rss.entries[0].link).hexdigest() |
| 21 | ||
| 22 | - | # print(cont) |
| 22 | + | news_list = [{"title": i_title, 'href': j_href, 'hash': last_hash}
|
| 23 | - | print(dates) |
| 23 | + | for i_title, j_href, last_hash in list(zip(i_title, j_href, last_hash))] |
| 24 | ||
| 25 | # print(news_list) | |
| 26 | # print(rss.entries[0].title) | |
| 27 | # print(rss.entries[0].link) | |
| 28 | ||
| 29 | # этот кусок нужно поместить в отдельный файл | |
| 30 | ||
| 31 | rss_сheck_encode = feedparser.parse(url.encode('utf-8'))
| |
| 32 | ||
| 33 | this_hash = hashlib.md5(rss_сheck_encode.entries[0].title + rss_сheck_encode.entries[0].link).hexdigest() | |
| 34 | print(this_hash) |