-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed.py
28 lines (24 loc) · 890 Bytes
/
feed.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
# -*- coding: utf-8 -*-
import pymysql
import feedparser
import re
myfeed = feedparser.parse("https://aws.amazon.com/about-aws/whats-new/recent/feed/")
db = pymysql.connect(
host='<Aurora MySQL Writer Endpoint>',
user='<user name>',
password='<password>',
database='<sample schema (ex: bedrockdb)>',
charset="utf8",
cursorclass=pymysql.cursors.DictCursor)
with db:
with db.cursor() as cur:
for item in myfeed['items']:
title = item.title
link = item.link
description = re.sub(r'<[^>]+>', '', item.description).replace("'", "\\'").replace('"', '\\"').replace('\n', ' ')
print (title)
print (link)
print (description)
cur.execute("INSERT INTO t_feed (title, link, description) VALUES (%s, %s, %s)", (title, link, description))
db.commit()
print ('Import rss Succesfull!')