sys.exit(1)
        try:
            client = gdata.calendar.client.CalendarClient(
                source='gnome-shell-google-calendar')
            client.ClientLogin(account, password, client.source)
        except Exception as e:
            print 'Error logging in as \'%s\'' % account
            print '%s' % e.args
            #print ('Invalid credentials for: \'%s\'.') % account
            sys.exit(1)

    else:
        while not client:
            print "Logging in as '%s'..." % account
            try:
                client = oauth.oauth_login(account)
            except Exception:
                print 'Error logging in as \'%s\'' % account
                print(
                    '\'%s\' may not be a GNOME online account. '
                    'A list of existing accounts is below.') % account
                print(
                    'If you do not see a list of accounts, '
                    'then you first need to add one.')
                print(
                    'For more information, see '
                    'http://library.gnome.org/users/gnome-help/stable/'
                    'accounts.html')
                try:
                    account = oauth.oauth_prompt()
                except ValueError:
예제 #2
0
#! /usr/bin/env python
#
# Ben Osment
# Sat Apr 28 11:41:18 2012

import oauth
import time
import unicodedata
import re

# create a new authenticated instance of the API
api = oauth.oauth_login()

def download_tweets(corpus_name, query, threshold):
    max_tweets_per_hr  = 325
    download_pause_sec = 3600 / max_tweets_per_hr

    # open corpus file, append new entries
    # try:
    #     # if the file exists, read number of exisiting entries
    #     # and append new entries to the end
    #     corpus = open(corpus_name, 'r+')
    #     num_entries = 0
    #     for line in corpus:
    #         num_entries += 1
    #     print "found exisiting file with", num_entries, "tweets"
    # except IOError:
    #     # otherwise, create a new file for writing the tweets
    #     print "creating new file", corpus name

    num_pos_entries = 0
    account = None
    for o, a in opts:
        if o == '--hide-cal':
            SHOW_SHORT_CALENDAR_TITLE = False
        if o == '--account':
            account = a

    if not account:
        account = config.get('account')

    # Login
    client = None
    while not client:
        print "Logging in as '%s'..." % account
        try:
            client = oauth.oauth_login(account)
        except Exception as e:
            print 'Error logging in as \'%s\'' % account
            print ('\'%s\' may not be a GNOME online account. '
                    'A list of existing accounts is below.') % account
            print ('If you do not see a list of accounts, '
                    'then you first need to add one.')
            print ('For more information, see '
                    'http://library.gnome.org/users/gnome-help/stable/'
                    'accounts.html')
            try:
                account = oauth.oauth_prompt()
            except ValueError as e:
                print ('You have entered an invalid account number. '
                        'Please enter an integer.')
            config.set('account', account)
예제 #4
0
import twitter
import sys
import re 
import csv

DEBUG = 0

if(len(sys.argv) != 3) :
    print "Error: Incorrect usage. Use %s <product-name> <limit>" %(sys.argv[0]) 
    sys.exit(1)

input_file = sys.argv[1]
search_term=sys.argv[1]
limit = sys.argv[2]
limit = limit if limit < 100 else 100
twitter_api = oauth_login()
twitter_rest = twitter.Twitter(auth=twitter_api.auth)
#stream = twitter_stream.statuses.filter(track=search_term,language='en')
rest = twitter_rest.search.tweets(q=search_term, lang='en')

if not DEBUG : 
 out = open('../2-extracted_tweets/'+input_file+'.csv','w') 
 writer = csv.writer(out, delimiter = '\t') 
 writer.writerow([
                    'username', 
                    'tweet', 
                    'timestamp',
                    ])

i = 0
prev_tweet = ''