Esempio n. 1
0
def tweet_from_jso_to_DB_test():
    """TODO
    #open json file
    #parse json files using json library
    #use dictionaries to store Tweet models (Tweet from dictionary already implemented)

    """

    twitterAPIfactory = TwitterAPIFactory()
    api = twitterAPIfactory.getAPI()

    last_tweet_recorded = Tweet.query.first()
    print last_tweet_recorded
    kw = {}
    if last_tweet_recorded:
        tweet_id = int(last_tweet_recorded.tweet_id)
        kw['since_id'] = tweet_id
    results = api.GetHomeTimeline(count=10, **kw)
    tweets = results
    #tweets[0].id = 9598979 reference in DB

    jsonfilename = 'tweet.json'

    tweetsJsonContent = [tweet.AsDict() for tweet in tweets]

    saveAsJSON(JSONSerializableObject=tweetsJsonContent,
               jsonfilename=jsonfilename,
               indent=4)
    parsedTweets = parseJSON(jsonfilename=jsonfilename)
    for parsedTweet in parsedTweets:
        my_tweet = Tweet.from_dictionary(parsedTweet)
        print "Parsed Tweet: %s" % (my_tweet)
def tweet_from_jso_to_DB_test():
    """TODO
    #open json file
    #parse json files using json library
    #use dictionaries to store Tweet models (Tweet from dictionary already implemented)

    """

    twitterAPIfactory = TwitterAPIFactory()
    api = twitterAPIfactory.getAPI()

    last_tweet_recorded = Tweet.query.first()
    print last_tweet_recorded
    kw = {}
    if last_tweet_recorded:
        tweet_id = int(last_tweet_recorded.tweet_id)
        kw['since_id'] = tweet_id
    results = api.GetHomeTimeline(count=10, **kw)
    tweets = results
    #tweets[0].id = 9598979 reference in DB 

    jsonfilename='tweet.json'

    tweetsJsonContent = [tweet.AsDict() for tweet in tweets]

    saveAsJSON(JSONSerializableObject=tweetsJsonContent,jsonfilename=jsonfilename,indent=4)
    parsedTweets = parseJSON(jsonfilename=jsonfilename)
    for parsedTweet in parsedTweets:
        my_tweet = Tweet.from_dictionary(parsedTweet)
        print "Parsed Tweet: %s" %(my_tweet)
Esempio n. 3
0
def tweet_from_json_to_db(jsonfilename):
    parsedTweets = parseJSON(jsonfilename=jsonfilename)
    for parsedTweet in parsedTweets:
        tweet = Tweet.from_dictionary(parsedTweet)
        print "Parsed Tweet: %s" % (tweet)
        print "Storing Tweet into DB..."
        tweet.submit()  # SAVES INTO DATABASE
def tweet_from_json_to_db(jsonfilename):
    parsedTweets = parseJSON(jsonfilename=jsonfilename)
    for parsedTweet in parsedTweets:
        tweet = Tweet.from_dictionary(parsedTweet)
        print "Parsed Tweet: %s" %(tweet)
        print "Storing Tweet into DB..."
        tweet.submit() # SAVES INTO DATABASE