def __init__(self):
    # We're running inside an instance
    cfg.update_from_metadata()
    util.setup_api(service_account=True)

    # Just for addinstance
    self.spawn_scheduler = util.Scheduler(cfg.num_workers)
    # For monitoring, deletion, anything else. We can be doing more of these at
    # a time without threatening API quota limits
    self.other_scheduler = util.Scheduler(cfg.num_workers * 2)
    self.state = CluserState.DOWN
    self.instances = {}
    self.errors = []
    self.first_free_slave = 0
    self.live_slaves = 0
    # For long-running remote tasks, such as transfers. Each operation is a
    # dictionary with state and original parameters.
    self.operations = {}
    self.op_counter = 0
    # This protects writing: self.state, state of each self.instances,
    # self.live_slaves
    self.cv = threading.Condition()
    # This is data forwarded to us about the status of the JobTracker
    self.latest_data = {}
    self.last_update = 0
    def __init__(self):
        # We're running inside an instance
        cfg.update_from_metadata()
        util.setup_api(service_account=True)

        # Just for addinstance
        self.spawn_scheduler = util.Scheduler(cfg.num_workers)
        # For monitoring, deletion, anything else. We can be doing more of these at
        # a time without threatening API quota limits
        self.other_scheduler = util.Scheduler(cfg.num_workers * 2)
        self.state = CluserState.DOWN
        self.instances = {}
        self.errors = []
        self.first_free_slave = 0
        self.live_slaves = 0
        # For long-running remote tasks, such as transfers. Each operation is a
        # dictionary with state and original parameters.
        self.operations = {}
        self.op_counter = 0
        # This protects writing: self.state, state of each self.instances,
        # self.live_slaves
        self.cv = threading.Condition()
        # This is data forwarded to us about the status of the JobTracker
        self.latest_data = {}
        self.last_update = 0
Ejemplo n.º 3
0
def setup():
    # CHANGE ME
    cfg.set_bucket('GS-bucket')
    cfg.project_id = 'compute-project-name'

    if os.path.exists('secret'):
        cfg.secret = open('secret').read().rstrip()
    if not cfg.secret:
        print 'Run tools/gen_passwd.py first to generate a password.'
        sys.exit(1)
    util.setup_api(service_account=False)
def setup():
  # CHANGE ME
  cfg.set_bucket('GS-bucket')
  cfg.project_id = 'compute-project-name'

  if os.path.exists('secret'):
    cfg.secret = open('secret').read().rstrip()
  if not cfg.secret:
    print 'Run tools/gen_passwd.py first to generate a password.'
    sys.exit(1)
  util.setup_api(service_account=False)
Ejemplo n.º 5
0
def main():
    unfollow_counter = 0
    keep_follow_counter = 0
    api = setup_api(consumer_key, consumer_secret, access_key, access_secret)
    friends = []
    try:
        # friends = Cursor(api.friends).items()
        i = 0
        for page in Cursor(api.friends).pages():
            print 'page: ', i
            print len(page)
            i += 1
            # while len(page) > 0:
            #     friend = page.pop()
            #     if need_unfollow(api, friend):
            #         print friend.name, ' has been unfollowed'
            #         unfollow(api, friend)
            #         unfollow_counter += 1
            #     else:
            #         print 'keep following ', friend.name
            #         keep_follow_counter += 1
            friends.extend(page)
            time.sleep(60)
            print len(friends), i - 1
        print len(friends)
    except TweepError, e:
        print e
        d = api.rate_limit_status()
        print d
        for i,j in d['resources']['friends'].iteritems():
            print i, j
            print(datetime.fromtimestamp(int(j['reset'])).strftime('%Y-%m-%d %H:%M:%S'))
def main():
    local_tz = time.timezone / (60 * 60)
    current_hour = (datetime.now().hour + (7 + local_tz)) % 24  # to GMT +7
    if 0 < current_hour < 5:
        print 'too late to tweet'
        return
    api = setup_api(consumer_key, consumer_secret, access_key, access_secret)

    dbconn = DBConn()
    post_table = 'tw'
    id_column = 'id'
    name_column = 'tweet'
    q_num_post = 'SELECT COUNT(*) FROM ' + post_table #calculate the total of rows data in the table
    num_post = dbconn.read(q_num_post)
    numb_post = num_post[0][0]
    #print num_post[0][0]

    query = 'SELECT ' + id_column + ',' + name_column + ' FROM ' + post_table #query for selecting the data tweet in the table
    a = dbconn.read(query)
    rand_number = randint(0, numb_post) #generate random number for randoming the data
    id_status = str(a[rand_number][0])
    status = str(a[rand_number][1])
    print id_status, status
    api.update_status(status) #for update status (tweet)
    query_delete = 'DELETE FROM ' + post_table + ' WHERE ' + id_column + ' = ' + id_status #query for deleting the data tweet in the table after updated
    ex = dbconn.delete(query_delete)
    print ex
Ejemplo n.º 7
0
def main():
    api = setup_api(consumer_key, consumer_secret, access_key, access_secret)
    file_path = 'Name of List accounts'
    accounts = read_list(file_path)
    for account in accounts:
        try:
            friend = api.create_friendship(account)
            if friend.screen_name == account:
                print 'Follow ' + account + ' success'
            else:
                print 'Follow ' + account + ' failed'
        except tweepy.TweepError, e:
            print e
def main():
    api = setup_api(consumer_key, consumer_secret, access_key, access_secret)
    file_path = 'Name of List accounts'
    accounts = read_list(file_path)
    for account in accounts:
	try:
		friend = api.create_friendship(account)
		if friend.screen_name == account:
			print 'Follow ' + account + ' success'
		else:
			print 'Follow ' + account + ' failed'
	except tweepy.TweepError, e:
		print e
Ejemplo n.º 9
0
def main():
    local_tz = time.timezone / (60 * 60)
    current_hour = (datetime.now().hour + (7 + local_tz)) % 24  # to GMT +7
    if 0 < current_hour < 5:
        print 'too late to tweet'
        return
    api = setup_api(consumer_key, consumer_secret, access_key, access_secret)

    rand_number = randint(0, 10)
    if rand_number % 7 == 0:
        status = get_link()
    else:
        status = get_status(STATUS_FILE)
    print status
    api.update_status(status)
Ejemplo n.º 10
0
def main():
    api = setup_api(consumer_key, consumer_secret, access_key, access_secret)

    file_path = "tweets.txt"
    tweet_data = read_list(file_path)
    tweet_text = pick_random_element(tweet_data)
    # get target
    target_accounts = api.friends()
    done = False
    while not done:
        target_account = pick_random_element(target_accounts)
        is_followed = is_followed_by(api, target_screen_name=target_account.screen_name)
        if is_good_account(target_account) and not is_followed:
            reply(api, tweet_text, target_account)
            done = True
Ejemplo n.º 11
0
def main_unfollow_all():
    api = setup_api(consumer_key, consumer_secret, access_key, access_secret)
    i = 0
    try:
        for page in Cursor(api.friends).pages():
            print 'page:', i
            i += 1
            for friend in page:
                try:
                    unfollow(api, friend)
                    print 'Unfollow', friend.screen_name
                except TweepError, e:
                    print 'Cannot unfollow', friend.screen_name, e
            time.sleep(60)
    except TweepError, e:
        print e
Ejemplo n.º 12
0
def main():
    ids = []
    listfollowers =[]
    i =0
    save_file = open("list_followers.txt","rw+")
    api = setup_api(consumer_key, consumer_secret, access_key, access_secret)
    for page in tweepy.Cursor(api.followers,screen_name="NameofAccount").pages():
        i +=1
	#use cursor for bypass 20 view limit from twitter
        while len(page) >0:
            listfollowers = page.pop()
            if is_good_account(listfollowers):
                print>> save_file,listfollowers.screen_name
                print listfollowers.screen_name
        ids.extend(page)
        time.sleep(60)
Ejemplo n.º 13
0
def main():
    api = setup_api(consumer_key, consumer_secret, access_key, access_secret)
    print "Loading followers.."
    followers = []
    for follower in tweepy.Cursor(api.followers).items():
        time.sleep(60)
        followers.append(follower)

    print "Found %s followers, finding friends.." % len(followers)
    friends = []
    for friend in tweepy.Cursor(api.friends).items():
        time.sleep(60)
        friends.append(friend)

    friend_dict = {}
    for friend in friends:
        friend_dict[friend.id] = friend

    follower_dict = {}
    for follower in followers:
        follower_dict[follower.id] = follower

    non_friends = [
        friend for friend in friends if friend.id not in follower_dict
    ]

    print "Unfollowing %s people who don't follow you " % len(non_friends)
    print "This will take approximately %s minutes." % (len(non_friends) /
                                                        60.0)
    answer = raw_input("Are you sure? [Y/n]").lower()
    if answer and answer[0] != "y":
        sys.exit(1)

    for nf in non_friends:
        print "Unfollowing %s" % nf.screen_name
        try:
            nf.unfollow()
        except:
            print "  .. failed, sleeping for 5 seconds and then trying again."
            time.sleep(5)
            nf.unfollow()
        print " .. completed, sleeping for 1 second."
        time.sleep(1)
Ejemplo n.º 14
0
def main():
    api = setup_api(consumer_key, consumer_secret, access_key, access_secret)
    file_path = 'famous_accounts.txt'
    accounts = read_list(file_path)
    for account in accounts:
        print '### From follower of ', account
        try:
            followers = api.followers(account)
            for follower in followers:
                if is_good_account(follower):
                    print follower.screen_name
                    try:
                        friend = api.create_friendship(follower.screen_name)
                        if friend.screen_name == follower.screen_name:
                            print 'Follow ' + follower.screen_name + ' success'
                        else:
                            print 'Follow ' + follower.screen_name + ' failed'
                    except tweepy.TweepError, e:
                        print e
        except Exception, e:
            print e
def main():
    api = setup_api(consumer_key, consumer_secret, access_key, access_secret)
    print "Loading followers.."
    followers = []
    for follower in tweepy.Cursor(api.followers).items():
        time.sleep(60)
        followers.append(follower)

    print "Found %s followers, finding friends.." % len(followers)
    friends = []
    for friend in tweepy.Cursor(api.friends).items():
        time.sleep(60)
        friends.append(friend)

    friend_dict = {}
    for friend in friends:
        friend_dict[friend.id] = friend

    follower_dict = {}
    for follower in followers:
        follower_dict[follower.id] = follower

    non_friends = [friend for friend in friends if friend.id not in follower_dict]

    print "Unfollowing %s people who don't follow you " % len(non_friends)
    print "This will take approximately %s minutes." % (len(non_friends) / 60.0)
    answer = raw_input("Are you sure? [Y/n]").lower()
    if answer and answer[0] != "y":
        sys.exit(1)

    for nf in non_friends:
        print "Unfollowing %s" % nf.screen_name
        try:
            nf.unfollow()
        except:
            print "  .. failed, sleeping for 5 seconds and then trying again."
            time.sleep(5)
            nf.unfollow()
        print " .. completed, sleeping for 1 second."
        time.sleep(1)
Ejemplo n.º 16
0
def main():
    unfollow_counter = 0
    keep_follow_counter = 0
    api = setup_api(consumer_key, consumer_secret, access_key, access_secret)
    friends = []
    try:
        # friends = Cursor(api.friends).items()
        i = 0
        #page =7
        for page in Cursor(api.friends).pages():
            print 'page: ', i
            print len(page)
            i += 1
            while i > 0:
                #i +=1
                while len(page) > 0:
                    friend = page.pop()
                    if need_unfollow(api, friend):
                        print friend.name, friend.screen_name, ' has been unfolloweddd'
                        unfollow(api, friend)
                        unfollow_counter += 1
                    else:
                        print 'keep following ', friend.name, friend.screen_name
                        keep_follow_counter += 1
                friends.extend(page)
                time.sleep(60)
                print 'while len page ', len(friends), i
                break
            time.sleep(60)
            print 'while i ', i
        print 'for', len(friends)
    except TweepError, e:
        print e
        d = api.rate_limit_status()
        print d
        for i, j in d['resources']['friends'].iteritems():
            print i, j
            print(
                datetime.fromtimestamp(int(
                    j['reset'])).strftime('%Y-%m-%d %H:%M:%S'))
Ejemplo n.º 17
0
def main():
    local_tz = time.timezone / (60 * 60)
    #autotweet at the working time (indonesia)
    current_hour = (datetime.now().hour + (7 + local_tz)) % 24  # to GMT +7
    if 0 < current_hour < 5:
        print 'too late to tweet'
        return
    api = setup_api(consumer_key, consumer_secret, access_key, access_secret)

    dbconn = DBConn()
    post_table = 'tw' #name of table 
    name_column = 'tweet' #name of column
    q_num_post = 'SELECT COUNT(*) FROM ' + post_table #count the rows of data
    num_post = dbconn.read(q_num_post)
    numb_post =num_post[0][0] #get value from count of rows data
    #print num_post[0][0]

    #query for select tweets
    query = 'SELECT ' + name_column + ' FROM ' + post_table
    a = dbconn.read(query)
    rand_number = randint(0, numb_post)

    api.update_status(str(a[rand_number][0]))
Ejemplo n.º 18
0
def main():
    api = setup_api(consumer_key, consumer_secret, access_key, access_secret)
    # f = open(stat_file, 'a')
    number_follower = api.get_user
    print number_follower
Ejemplo n.º 19
0
#
# 4.  Execute this script: python unfollow.py

import time
import tweepy
import sys
import constants
from util import setup_api

# constants
consumer_key = constants.consumer_key
consumer_secret = constants.consumer_secret
access_key = constants.access_key
access_secret = constants.access_secret

api = setup_api(consumer_key, consumer_secret, access_key, access_secret)

print "Loading followers.."
follower_objects = [follower for follower in tweepy.Cursor(api.followers).items()]

print "Found %s followers, finding friends.." % len(follower_objects)
friend_objects = [friend for friend in tweepy.Cursor(api.friends).items()]

# create dictionaries based on id's for easy lookup
friends = dict([(friend.id, friend) for friend in friend_objects])
followers = dict([(follower.id, follower) for follower in follower_objects])

# find all your "non_friends" - people who don't follow you even though you follow them.
non_friends = [friend for friend in friend_objects if friend.id not in followers]

# double check, since this could be a rather traumatic operation.