-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_categories.py
37 lines (36 loc) · 1.26 KB
/
update_categories.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
import MySQLdb, config
sql = MySQLdb.connect(host="localhost",
user=config.username,
passwd=config.passwd,
db=config.db)
sql.query("SELECT `site` FROM `sites` ")
sites=sql.store_result().fetch_row(0)
output=""
def print_site_data(site):
output=""
output+= '"'+site[0]+'":{'
sql.query("SELECT `sites`.`site` , `url`, `section` FROM `feedurls` , `sites` WHERE `sites`.`site` = '"+site[0]+"'")
feeds=sql.store_result().fetch_row(0)
i=1
output+=print_feed_data(feeds[0])
while i<len(feeds):
output+= ","
output+=print_feed_data(feeds[i])
i+=1
output+= "}"
return output
def print_feed_data(feed):
output=""
output+= '"'+feed[2]+'":"'+feed[1]+'"'
return output
output+= "{"
i=1
output+=print_site_data(sites[0])
while i<len(sites):
output+= ","
output+=print_site_data(sites[i])
i+=1
output+=',"guardian":{"business":"business","education":"education","environment":"environment","film":"film","football":"football","media":"media","politics":"politics","science":"science","sport":"sport","technology":"technology","uk-news":"uk-news","world":"world"}'
output+= "}"
file=open('site/sites.json',"w")
file.write(output)