예제 #1
0
    def __update_relationships(self, principle):
        if self.user_id is None:
            return False

        principle_to_url_prototype = {
            'followed_by': selfFollowedBy,
            'follows': selfFollows
        }

        if principle not in principle_to_url_prototype.keys():
            return

        if get_self_id() != self.user_id:
            # relationship info accessible for access-token owner only
            return

        print "Updating relationship:", principle

        ids_to_names_dictionary = dict()
        url = get_url('', get_access_token(), principle_to_url_prototype[principle])
        while url is not None:
            raw_data = urllib2.urlopen(url).read()
            json_data = json.loads(raw_data)
            users = json_data['data']
            list_of_dictionaries = [{entry['id']: entry['username']} for entry in users]
            for d in list_of_dictionaries:
                ids_to_names_dictionary.update(d)
            url = get_next_url(json_data)
        aim_directory = self.dir + principle + '/'
        if not os.path.exists(aim_directory):
            os.mkdir(aim_directory)
        final_file = open(aim_directory + str(datetime.now().date()) + '.json', 'w')
        json.dump(ids_to_names_dictionary, final_file)
예제 #2
0
def get_self_id():
    global self_id
    if self_id is not None:
        return self_id
    url = get_self_url(get_access_token())
    raw_data = urllib2.urlopen(url).read()
    json_data = json.loads(raw_data)
    self_id = int(json_data['data']['id'])
    return self_id
예제 #3
0
    json.dump(data, ids_file)
    return data[username]


api = InstagramAPI(
                    client_id=authInfoProvider.get_client_id(),
                    client_secret=authInfoProvider.get_client_secret()
                   )

target_name = sys.argv[-1]

result = api.user_search(target_name)
user = [p for p in result if p.username == target_name]
if user:
    user = user[0]
else:
    print "User not found."

print "Found user:"******"-s" == sys.argv[-2]:
        need_to_update = False

if need_to_update:
    DataUpdater(user_id=userid, access_token=authInfoProvider.get_access_token()).update()


예제 #4
0
 def __init__(self, user_id):
     self.id = user_id
     self.access_token = get_access_token()
     self.info = dict()
     self.__load_info()
예제 #5
0
def update_all():
    d = get_name_to_id_dict_from_db()
    for name in d.keys():
        updater = DataUpdater(user_name=name, access_token=get_access_token())
        updater.update()
예제 #6
0
def update(user_name=None):
    d = get_name_to_id_dict_from_db()
    if user_name in d.keys():
        updater = DataUpdater(user_id=d[user_name], access_token=get_access_token())
        updater.update()