-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
79 lines (71 loc) · 2.43 KB
/
db.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import sqlite3
import feedparser
import Gui
def main():
conn = sqlite3.connect('jobs.db')
c = conn.cursor()
create_db(c)
populate_db(c)
Gui.display_titles(c)
conn.commit()
c.close()
conn.close()
def create_db(c):
c.execute("""DROP TABLE IF EXISTS jobs""")
c.execute("""CREATE TABLE IF NOT EXISTS jobs(
title text,
tags text,
author text,
date_published text,
description text,
location text,
links text,
allows_remote text
)""")
def populate_db(c):
feed = feedparser.parse("https://stackoverflow.com/jobs/feed")
length = len(feed['entries'])
for x in range(length):
if 'title' in feed['entries'][x]:
currTitle = feed['entries'][x]['title']
if currTitle.find("allows remote") != -1:
currRemote = "yes"
else:
currRemote = "no"
else:
currTitle = "none"
if 'tags' in feed['entries'][x]:
currTags = ' '.join(str(e) for e in feed['entries'][x]['tags'])
else:
currTags = "none"
if 'author' in feed['entries'][x]:
currAuthor = feed['entries'][x]['author']
else:
currAuthor = "none"
if 'published' in feed['entries'][x]:
currDate = feed['entries'][x]['published']
else:
currDate = "none"
if 'summary' in feed['entries'][x]:
currDescription = feed['entries'][x]['summary']
else:
currDescription = "none"
if 'location' in feed['entries'][x]:
currLocation = feed['entries'][x]['location']
else:
currLocation = "none"
if 'links' in feed['entries'][x]:
currLinks = ' '.join(str(e) for e in feed['entries'][x]['links'])
else:
currLinks = "none"
c.execute("INSERT INTO jobs VALUES (:title, :tags, :author, :date_published, :description, :location, :links, :allows_remote)",
{'title': currTitle,
'tags': currTags,
'author': currAuthor,
'date_published': currDate,
'description': currDescription,
'location': currLocation,
'links': currLinks,
'allows_remote': currRemote
})
main()