class MyForm(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.db = ComicsDB('data.db') self.ui = Ui_MainWindow() self.ui.setupUi(self) self.score = 0 self.ui.label.setText("Score : %d" % self.score) def checkAnswer(self, x): x = x - 1 if x == self.t: self.score = self.score + 1 self.ui.label.setText("Score : %d" % self.score) self.load() else: self.ui.textEdit.setText("Your Answer is not correct, please try again or hit reload to change question.") def load(self): id = random.randrange(1,842,1) alt = "Alt Text : " + self.db.getAlt(id) titlet = self.db.getTitle(id) title = [self.db.getTitle(random.randrange(1,840,1))] for i in range(1,5): title.append(self.db.getTitle(random.randrange(1,840,1))) self.t = random.randrange(0,5,1) title[self.t] = titlet self.ui.retranslateUi(self, title[0], title[1], title[2], title[3], title [4]) self.ui.textEdit.setText(alt)
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.db = ComicsDB('data.db') self.ui = Ui_MainWindow() self.ui.setupUi(self) self.score = 0 self.ui.label.setText("Score : %d" % self.score)
from database import ComicsDB def parse_page(id): page_url = "http://xkcd.com/%s/" % id page = html.parse(urlopen(page_url)).getroot() title = page.cssselect("#ctitle")[0].text image_url = page.cssselect("div#comic img")[0].attrib['src'] alt = page.cssselect("div#comic img")[0].attrib['title'] transcript = page.cssselect("#transcript")[0].text return (id, title, alt, transcript, image_url) if __name__ == "__main__": if len(sys.argv) < 3: print "Usage: %s <filename> <startid>" % sys.argv[0] sys.exit() file_name = sys.argv[1] db = ComicsDB(file_name) id = int(sys.argv[2]) while True: if id != 404: #http://xkcd.com/404 is an obvious joke. if not db.get(id): comic_data = parse_page(id) db.put(*comic_data) print "Done %d" % id id += 1
# exkayseedee.py # Game Idea By : YuviPanda # Author : Hiemanshu Sharma # # from database import ComicsDB import os import random import sys DOCUMENTATION = "" check = os.path.isfile('data.db') if (check): cdb = ComicsDB('data.db') score = 0 id = random.randrange(1,840,1) #fix alt = cdb.getAlt(id) title = cdb.getTitle(id) print "Alt Text : %s" %alt t = random.randrange(1,6,1) #fix ch = 1; for i in range(1,6): rand = random.randrange(1,840,1) #fix if (i != t): if (rand != id): print "%d %s" %(i, cdb.getTitle(rand)) else: print "%d %s" %(t, title) while True:
import sys import json from database import ComicsDB if __name__ == "__main__": db = ComicsDB(sys.argv[1]) comics = db.get_all() titles = ("id", "title", "alt", "transcript", "image_src") data = {"count": len(comics), "comics": dict([(int(comic[0]), dict(zip(titles, comic))) for comic in comics])} print json.dumps(data)