key = "XXXX"
        secret = "XXXX"

        access_token = "XXXX"
        access_token_secret = "XXXX"

        # authorize twitter, initialize tweepy
        auth = tweepy.OAuthHandler(key, secret)
        auth.set_access_token(access_token, access_token_secret)
        api = tweepy.API(auth)

        screen_name = 'triplejplays'

        limit = int(sys.argv[2]) if len(sys.argv) > 2 else 0  # ternary lols.

        db = accessDB.accessDatabase()

        # ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ #

        if str(sys.argv[1]) == "GET_ALL":
            parsedTweets = get_tweets(api, screen_name, limit=limit)

        # ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ #
        elif str(sys.argv[1]) == "GET_NEW":

            try:
                queryOut = dbQueries.getNewestEntryInDB(db)
                newestID = dbQueries.getEntryforRow(queryOut, 'id')
                print 'newest id was:', newestID, '\n'
                print queryOut, '\n************************\n'
示例#2
0
def runQuery(query=[]):

    if len(query) > 1:

        db = accessDB.accessDatabase()

        output = []

        if query[0] == "ARTIST_ANDOR_TIME":
            try:
                # Try and find args and values in the argv
                try:
                    artistIdx = query.index("-artist")
                    artistName = query[artistIdx + 1]
                except:
                    artistName = 0

                try:
                    startTimeIdx = query.index("-start")
                    startTime = query[startTimeIdx + 1]
                except:
                    startTime = 0

                try:
                    endTimeIdx = query.index("-end")
                    endTime = query[endTimeIdx + 1]
                except:
                    endTime = 0

                output = songsByArtistInPeriod(db, artist=artistName, startTime=startTime, endTime=endTime)
                print output

            except Exception,e:
                print "Query 'ARTIST_ANDOR_TIME' takes -artist -start & -end arguments... have fun!"
                print e

        if query[0] == "TOP_N_IN_TIME":
            try:
                # Try and find args and values in the argv
                try:
                    topNIdx = query.index("-topN")
                    topN = query[topNIdx + 1]
                except:
                    topN = 20 # a default value
                try:
                    startTimeIdx = query.index("-start")
                    startTime = query[startTimeIdx + 1]
                except:
                    startTime = 0

                try:
                    endTimeIdx = query.index("-end")
                    endTime = query[endTimeIdx + 1]
                except:
                    endTime = 0

                output = topSongsInPeriod(db, count=topN, startTime=startTime, endTime=endTime)
                print output
            
            except Exception,e:
                print "Query 'TOP_N_IN_TIME' takes -countN -start & -end arguments... get emmmm"
                print e