Example #1
0
def robotsubmission():
    print >> sys.stderr, "Received GET request to /robotsubmission."
     # Twitter handle received
    if request.method == 'POST':
        try:
            ##try:
            # Checks if bot already exists.
            twitterhandle = request.form['twitterhandle']
            ##test = Bot.query.filter(Bot.bothandle == '@'+ str(twitterhandle)).first()
            ##testquery = str(test.bothandle[1:])
            ##print testquery
            newshelf = shelve.open('botcachedb2')
            newnewshelf = []
            for key in newshelf.keys():
                newnewshelf.append(key.lower())
            if twitterhandle.lower() in newnewshelf:
                return render_template('alreadyexists.html',twitterhandle=twitterhandle,css=css,smlogo=smlogo,\
                                                           pythonpage=pythonpage,htmlpage=htmlpage)
            else:
            ##except:
                try:
                    xx = jsonjson("http://api.twitter.com/1/users/show.json?screen_name=%s" % twitterhandle)
                    created_at = ""
                    created_at = xx['created_at']
                    created_at = created_at.split()
                    created_at = str(created_at[1]) + " " + str(created_at[2]) + ", " + str(created_at[5]) + " " + str(created_at[3])
                except:
                    print >> sys.stderr, str(sys.exc_info()[0]) # These write the nature of the error
                    print >> sys.stderr, str(sys.exc_info()[1])
                finally:
                    # API requests via Twitter helper library
                    botuser = api.GetUser(str(twitterhandle))
                    friendscount = botuser.GetFriendsCount()
                    followerscount = botuser.GetFollowersCount()
                    botlocation = botuser.GetLocation()
                    botname = botuser.GetName()
                    botdesc = botuser.GetDescription()
                    botdesc = botdesc
                    boturl = botuser.GetUrl()
                    bottimezone = botuser.GetTimeZone()
                    imgurl = botuser.GetProfileImageUrl()

                    # Posts a note that the bot is being considered. Just used for testing.
                    #api.PostUpdate("New bot %s is now being considered! Visit LINK to cast your vote." % twitterhandle)
                    
                    return render_template('robotsubmission.html',twitterhandle=twitterhandle,imgurl=imgurl,\
                                           botdesc=botdesc,botlocation=botlocation,botname=botname,\
                                               followerscount=followerscount,friendscount=friendscount,\
                                                   created_at=created_at,boturl=boturl,bottimezone=bottimezone,\
                                                       css=css,smlogo=smlogo,\
                                                           pythonpage=pythonpage,htmlpage=htmlpage)
        except:
            print >> sys.stderr, str(sys.exc_info()[0]) # These write the nature of the error
            print >> sys.stderr, str(sys.exc_info()[1])
    else:
        return "Error"
Example #2
0
def botfavorites(bothandle):
    newshelf = shelve.open('botcachedb2')
    try:
        singlebot = newshelf['@' + str(bothandle)]
        discussiontopics = singlebot.discussiontopics[3:-2]
        
        y = jsonjson('https://api.twitter.com/1/statuses/user_timeline.json?count=200&screen_name=%s&include_rts=1&include_entities=true' % bothandle)
        twittertimeline = []
        for tweet in y:
            if tweet['retweet_count'] > 3:
                twittertimeline.append(tweet)
        return render_template('botpagefavorites.html',css=css,smlogo=smlogo,bothandle=bothandle,\
                               twittertimeline=twittertimeline,singlebot=singlebot,\
                                   pythonpage=pythonpage,htmlpage=htmlpage)
    except:
        print >> sys.stderr, str(sys.exc_info()[0]) # These write the nature of the error
        print >> sys.stderr, str(sys.exc_info()[1])
Example #3
0
print " "
print "--- BotCache ---"
print " "

for bot in botcacheshelf.values():
    print "bot: " + str(bot.bothandle) + " | " + str(bot.status)

print " "
nextstep = raw_input("New bot or modify bot status? (n or m) ")

if nextstep == 'n':
    twitterhandle = raw_input("Enter bot handle (no @ sign) ") 
    if "@" + str(twitterhandle) in botcacheshelf.keys():
        print "Oops, bot already in database"
    else:
        xx = jsonjson("http://api.twitter.com/1/users/show.json?screen_name=%s" % twitterhandle)
        created_at = xx['created_at']
        created_at = created_at.split()
        created_at = str(created_at[1]) + " " + str(created_at[2]) + ", " + str(created_at[5]) + " " + str(created_at[3])
        
        # API requests via Twitter helper library
        bothandle = "@" + str(twitterhandle)
        botuser = api.GetUser(str(twitterhandle))
        friendscount = botuser.GetFriendsCount()
        followerscount = botuser.GetFollowersCount()
        botlocation = botuser.GetLocation()
        botname = botuser.GetName()
        botdesc = botuser.GetDescription()
        botdesc = botdesc
        boturl = botuser.GetUrl()
        bottimezone = botuser.GetTimeZone()