import sys import re import MySQLdb connection = MySQLdb.connect(host="localhost", \ user="plusmobile", passwd="reify-plusmobile", \ db="plusmobile") cursor = connection.cursor() feedList = [] widgetList = [] filter = re.compile(r'boobs|porn|fucking|pussy') def readfile(): f = open("sorted_feed_list", "rb") for line in f: if not filter.match(line.lower()): feedList.append(line.strip("\n")) f.close() def getchannels(dbcursor): print "getting channels...", sys.stdout.flush() count = 0 for url in feedList: dbcursor.execute("select p.text, p.description, p.image, i.xmlqueryUrl from pages p, page_items i where p.pageid=i.pageid and p.type='starterPack' and i.xmlqueryurl=%s", url) row = dbcursor.fetchone() if row: widgetList.append(row) else: print "No channel:", url count+= 1 if count % 50 == 0: print count,".. ", sys.stdout.flush() #if count == 300: break print "done." sys.stdout.flush() def writePythonWidgetList(): f = open("recentWidgets.py","w"); f.write("W=[") count = 0 for w in widgetList: if count != len(widgetList)-1: f.write("[\"%s\", \"%s\", \"%s\", \"%s\"],\n" % (w[0].replace('"', '\\"'),w[1].replace('"', '\\"'),w[2].replace('"', '\\"'),w[3].replace('"', '\\"'))) else: f.write("[\"%s\", \"%s\", \"%s\", \"%s\"]\n" % (w[0].replace('"', '\\"'),w[1].replace('"', '\\"'),w[2].replace('"', '\\"'),w[3].replace('"', '\\"'))) count += 1 f.write("]\n") f.close() readfile() getchannels(cursor) writePythonWidgetList()