Exemple #1
0
 def populateResultsPage(self):
     file = open("filmTitle.txt", "r")
     lines = file.readlines()
     rdate = lines[1].strip()
     tableName = lines[0].strip()
     api = TwitterAPI.TwitterClient()
     weekNO = api.getWeekNO(rdate)
     polarity = api.countPostiveTweets(
         tableName, weekNO) / api.countNegativeTweets(tableName, weekNO)
     subjectivity = (api.countPostiveTweets(tableName, weekNO) +
                     api.countNegativeTweets(tableName, weekNO)
                     ) / api.countNeutralTweets(tableName, weekNO)
     self.polarityResult.config(text=str(polarity))
     self.subjectivityResult.config(text=str(subjectivity))
     self.weekResult.config(text=str(weekNO))
     #now to get the chnage in polarity and subjectivity
     try:
         polarityChange = polarity - (
             api.countPostiveTweets(tableName, (weekNO - 1)) /
             api.countNegativeTweets(tableName, (weekNO - 1)))
         subjectivityChange = subjectivity - (
             (api.countPostiveTweets(tableName, (weekNO - 1)) +
              api.countNegativeTweets(tableName, (weekNO - 1))) /
             api.countNeutralTweets(tableName, (weekNO - 1)))
         #now i will set all the labels to the new values
         self.polarityCResult.config(text=str(polarityChange))
         self.subjectivityCResult.config(text=str(subjectivityChange))
     except ZeroDivisionError:
         self.polarityCResult.config(text="N/A")
         self.subjectivityCResult.config(text="N/A")
Exemple #2
0
 def searchTwitterAPI(self):
     query = str(self.filmEntry.get())
     releaseDate = str(self.rdEntry.get())
     dbTableName = str(query.replace(" ", ""))
     filmTitleFile = open("filmTitle.txt", "w")
     filmTitleFile.write(str(dbTableName) + "\n")
     filmTitleFile.write(releaseDate)
     filmTitleFile.close()
     api = TwitterAPI.TwitterClient()
     weekNo = api.getWeekNO(releaseDate)
     tableExists = api.createDBTable(dbTableName)
     if tableExists:
         #check if there are tweets with the same week number if there are
         #and the weekNO is differenet then we search for tweets and add them
         #else we just continue
         cur.execute(
             """SELECT COUNT(*) FROM """ + str(dbTableName) +
             """ WHERE weekNo=?""", (weekNo, ))
         if cur.fetchone()[0] >= 1:
             self.goToResults()
         else:
             tweets = api.getTweets(query)
             api.populateDB(dbTableName, tweets, weekNo)
             api.populateReultsTable(dbTableName, weekNo)
             self.goToResults()
     else:
         tweets = api.getTweets(query)
         #now we will see if the table is in the database and if it is we will
         #then check if the data we are adding is new if it is the it will be added to the db
         api.createDBTable(dbTableName)
         api.populateDB(dbTableName, tweets, weekNo)
         api.populateReultsTable(dbTableName, weekNo)
         self.goToResults()