def main(): inicio = time.process_time() print("...Start liking at " + datetime.datetime.now().strftime("%c")) api = login() api.getProfileData() user_pk = api.LastJson['user']['pk'] user_pk = "904385495" user_followers = get_followers_pk(api, user_pk) get_user_followers = shuffle(user_followers) # /ecto:2058288265 /themacrowizard:2211285 /joseca_lifts:904385495 # potto:38273173 /iguazel:2647052134 /sirdavid10:289548141 /armando_firenze:185340079 /# r_marting:6363369111 x = 0 for f in get_user_followers: try: x += 1 t = time.process_time() print( "_________________________________________________________________________" ) print( str(x) + ": " + str(f) + ": Iniciando: " + str(datetime.datetime.now())) api.getUserFeed(f) info = api.LastJson t2 = time.process_time() - t print( str(x) + ": " + str(f) + ": Got JSON UserFeed: " + str(t2) + " seconds") img_id = info['items'][0]['id'] api.like(img_id) t3 = time.process_time() - t2 print( str(x) + ": " + str(f) + ": Post liked! " + str(t3) + " seconds") except IndexError: print("Index error") except KeyError: print("Key error") except BaseException as err: print(err) finally: t4 = time.process_time() print(str(x) + ": " + str(f) + ": Sleeping....... ") time.sleep(random.randint(60, 70)) t5 = time.process_time() - t4 print( str(x) + ": " + str(f) + ": Slept for " + str(t5) + " seconds") fin = time.process_time() - inicio print("...End working.... " + str(x) + " posts liked! " + str(fin))
def diego_devuelve_likes_a_ultimos_likers(): inicio = datetime.datetime.now() print("...Start liking.... at ... " + inicio.strftime("%c")) api = login() user_pk = "289060797" # PK DIEGO: modificar para dar likes a otros user_pk = "289060797" # /ecto:2058288265 /themacrowizard:2211285 /joseca_lifts:904385495 /sergio.espinar:644593827 # /diego 289060797 /potto 38273173 /iguazel:2647052134 /ecto:2058288265 /sirdavid10:289548141 /armando_firenze:185340079 x = 0 api.getUserFeed(user_pk) lj = api.LastJson post_id = lj['items'][0]['id'] print(post_id) api.getMediaLikers(post_id) likers = api.LastJson likers_len = len(likers['users']) print("Number of likers: ", likers_len) y = 0 for l in likers['users']: try: y += 1 user_posts = api.getUserFeed(l['pk']) post_id = api.LastJson['items'][0]['id'] api.like(post_id) print( str(x) + "/" + likers_len + ": " + datetime.datetime.now().strftime("%c") + " - " + str(l['username']) + ":" + str(l['pk']) + " post liked!") x += 1 t = datetime.datetime.now() print("Sleeping................................... ", end="") time.sleep(random.randint(60, 70)) t2 = datetime.datetime.now() - t print("Slept for: " + str(t2)) except IndexError as err: e = err except KeyError as err: e = err except BaseException as err: e = err fin = datetime.datetime.now() - inicio print("...End working.... " + str(x) + " posts liked! " + str(fin))
def diego_da_likes_a_followers_de_user(): inicio = datetime.datetime.now() print("...Start liking.... at ... " + inicio.strftime("%c")) api = login() api.getProfileData() user_pk = api.LastJson['user']['pk'] #user_pk = "904385495" getUserFollowers = get_followers_pk(api, user_pk) print(getUserFollowers) # /ecto:2058288265 /themacrowizard:2211285 /joseca_lifts:904385495 # potto:38273173 /iguazel:2647052134 /sirdavid10:289548141 /armando_firenze:185340079 /# r_marting:6363369111 x = 0 for f in getUserFollowers: try: t = datetime.datetime.now() print(str(x) + ": " + str(f) + " : Iniciando____________________") user_posts = api.getUserFeed(f) info = api.LastJson t2 = datetime.datetime.now() - t print(str(x) + ": " + str(f) + ": got JSON UserFeed " + t2) items = info['items'][0] last_post_img_url = items['image_versions2']['candidates'][0][ 'url'].split("?")[0] img_id = info['items'][0]['id'] api.like(img_id) t3 = datetime.datetime.now() - t2 print( str(x) + ": " + datetime.datetime.now().strftime("%c") + " - " + str(f) + " post liked!" + t3) x += 1 t4 = datetime.datetime.now() - t3 print(str(x) + ": " + str(f) + ": sleeping....... " + t4) time.sleep(1 + random.randint(5, 10)) t5 = datetime.datetime.now() - t4 print(str(x) + ": " + str(f) + ": slept " + t5) except IndexError: print("Index error") except KeyError: print("Key error") except BaseException as err: print(err) fin = datetime.datetime.now() - inicio print("...End working.... " + str(x) + " posts liked! " + str(fin))
def __main__(): api = login() api.getProfileData() inicio = datetime.datetime.now() print("Process started at ... " + inicio.strftime("%c")) user_pk = api.LastJson['user']['pk'] print(datetime.datetime.now()) followings_pk = get_followings(api, user_pk) file = open("followings.csv", "w") file.flush() x = 0 for f in followings_pk: print(str(x), ": ", str(f)) file.write(str(f) + ";" + "\n") file.flush() x += 1 file.flush() file.close() fin = datetime.datetime.now() - inicio print("...End working.... " + str(fin))
# diego_devuelve_likes # !/usr/bin/env python # -*- coding: utf-8 -*- from diego_util import login import datetime api = login() api.getProfileData() inicio = datetime.datetime.now() print("...Start liking.... at ... " + inicio.strftime("%c")) user_pk = api.LastJson['user']['pk'] user_posts = api.getUserFeed(user_pk) post_id = api.LastJson['items'][0]['id'] api.getMediaLikers(post_id) likers = api.LastJson num_likes = 0 for l in likers['users']: try: api.getUserFeed(l['pk']) api.like(api.LastJson['items'][0]['id']) num_likes += 1 print(str(l['username']) + " last post liked ") except IndexError as err: e = err except KeyError as err: e = err fin = datetime.datetime.now() - inicio print("...End working.... " + str(num_likes) + " given: " + str(fin))
def main(desde=None): inicio = datetime.datetime.now() print("...Start liking at ... " + inicio.strftime("%c")) api = login() user_pk = "289060797" # PK AYUNO_INTERMITENTE user_pk = "2211285" # /ecto:2058288265 /themacrowizard:2211285 /joseca_lifts:904385495 /sergio.espinar:644593827 # /marcos_gt:566286300 /guillenutriscientific:828934657 /thefitmedstudent:2205196357 # /neatfitcouple:5886520324 /j.a.roa:1539017410 /sergvlc:364963984 desde = 0 if desde is None else desde # Para que funcione desde el cero si no mandamos param de continuar fallido x, likes = 0, 0 api.getUsernameInfo(user_pk) username = api.LastJson['user']['username'] api.getUserFeed(user_pk) last_json = api.LastJson taken = int((time.time() - last_json['items'][0]['taken_at']) / 3600 / 24) # seconds to days post_id = last_json['items'][0]['id'] api.getMediaLikers(post_id) likers = api.LastJson likers_len = len(likers['users']) print("Liking user:"******", number of likes:", likers_len, ", post has", taken, "days old") for l in likers['users']: x += 1 try: print(str(x), "/", str(likers_len), ":", datetime.datetime.now().strftime("%c"), "/", str(l['username']), ":", str(l['pk']), end="") print("/Start new like /", end="") _ = api.getUserFeed(l['pk']) print("User feed retrieved /", end="") post_id = api.LastJson['items'][0]['id'] print("Post ID retrieved /", end="") likes += 1 # Cada 100 descansa para evitar spammeo if (likes % 100) == 0: print("Sleeping for 300s /", end="") time.sleep(300) if x > desde: api.like(post_id) print(" post liked!") else: print(" already liked!") except IndexError as err: print("", end="") print(datetime.datetime.now().strftime("%c"), "index errror: ", err) except KeyError as err: print("", end="") print(datetime.datetime.now().strftime("%c"), "Key error: ", err) except Exception as err: print("", end="") print(datetime.datetime.now().strftime("%c"), "exception: ", err) # TODO Si excepcion es por block, hacer un sleep de 5 mins y relanzarse a si # TODO mismo con el count del proceso por el que vamos finally: if x > desde: t = datetime.datetime.now() print("Sleeping................................... ", end="") time.sleep(random.randint(110, 130)) t2 = datetime.datetime.now() - t print("Slept for: " + str(t2)) fin = datetime.datetime.now() - inicio print("...End working.... " + str(likes) + " posts liked! " + str(fin)) winsound.Beep(2500, 250)
def diego_elimina_followers_0(): api = login() api.getProfileData() inicio = datetime.datetime.now() print("Process started at ... " + inicio.strftime("%c")) user_pk = api.LastJson['user']['pk'] followers_list = get_followers_full_TEST(api, user_pk, 50) print("Follower list obtained, length: " + str(len(followers_list))) print(datetime.datetime.now()) my_posts = get_user_posts(api, user_pk, 10) x = 0 unique_likers_pk = [] for post in my_posts: x += 1 post_id = post['id'] items = post['taken_at'] api.getMediaLikers(post_id) likers = api.LastJson y = 0 for l in likers['users']: y += 1 if l['pk'] not in unique_likers_pk: unique_likers_pk.append(l['pk']) if x == 10: break print(datetime.datetime.now().strftime("%c") + "Unique liking users list obtained, length: " + str(len(unique_likers_pk))) followers_have_not_liked = [] followers_have_liked = [] for f in followers_list: if f.pk not in unique_likers_pk: if f not in followers_have_not_liked: followers_have_not_liked.append(f) else: followers_have_liked.append(f) print(datetime.datetime.now()) print("Followers that havent liked a post list obtained, length: " + str(len(followers_have_not_liked))) print("Followers that have liked a post list obtained, length: " + str(len(followers_have_liked))) followings_pk = get_followings(api, user_pk) f_not_liked_not_followed_y_private = [] f_not_liked_not_followed_y_public_sin_posts = [] f_not_liked_not_followed_y_public_con_posts = [] f_not_liked_not_followed_y_public_con_pocos_posts = [] x = 0 for f in followers_have_not_liked: print(str(x) + ": Assigning follower " + f.username) x += 1 if f.pk not in followings_pk: if f.private: f_not_liked_not_followed_y_private.append(f) else: if f.has_posts == "F": f_not_liked_not_followed_y_public_sin_posts.append(f) elif f.has_posts == "T": posts = get_user_posts(api, f.pk) f.posts = len(posts) taken_at = posts[0]['taken_at'] f.msg = int((time.time() - taken_at) / 3600 / 24) # seconds to days # todo ver cuando publicó por última vez o si tiene < X posts if len(posts) >= 25: f_not_liked_not_followed_y_public_con_posts.append(f) else: f_not_liked_not_followed_y_public_con_pocos_posts.append( f) print("__________f_not_liked_not_followed_y_private: " + str(len(f_not_liked_not_followed_y_private))) for f in f_not_liked_not_followed_y_private: f.print() print("__________f_not_liked_not_followed_y_public_sin_posts: " + str(len(f_not_liked_not_followed_y_public_sin_posts))) for f in f_not_liked_not_followed_y_public_sin_posts: f.print() print("__________f_not_liked_not_followed_y_public_con_posts: " + str(len(f_not_liked_not_followed_y_public_con_posts))) for f in f_not_liked_not_followed_y_public_con_posts: f.print() print("__________f_not_liked_not_followed_y_public_con_pocos_posts: " + str(len(f_not_liked_not_followed_y_public_con_pocos_posts))) for f in f_not_liked_not_followed_y_public_con_pocos_posts: f.print() fin = datetime.datetime.now() - inicio print("...End working.... " + str(fin))
def lanzar_estadisticas(): api = login() api.getProfileData() inicio = datetime.datetime.now() print("Process started at ... " + inicio.strftime("%c")) user_pk = api.LastJson['user']['pk'] followers_list = get_followers_full_TEST(api, user_pk, 1000) print(datetime.datetime.now()) print("-----------------------------Follower list obtained, length: " + str(len(followers_list))) my_posts = get_user_posts(api, user_pk) x = 0 # file = open("diego_my_posts_likers.csv", "w") unique_likers_pk = [] for post in my_posts: x += 1 # file.write(str(x) + "LIKES;POST ID;USER_PK;USERNAME;" + "\n") post_id = post['id'] items = post['taken_at'] api.getMediaLikers(post_id) likers = api.LastJson y = 0 for l in likers['users']: y += 1 # file.write(str(y) + ";" + post_id + ";" + str(l['pk']) + ";" + str(l['username']) + "\n") # file.flush() if l['pk'] not in unique_likers_pk: unique_likers_pk.append(l['pk']) # file.close() print(datetime.datetime.now()) print("-----------------------------Unique liking users list obtained, length: " + str(len(unique_likers_pk))) followers_have_not_liked = [] followers_have_liked = [] for f in followers_list: if f.pk not in unique_likers_pk: if f not in followers_have_not_liked: followers_have_not_liked.append(f) else: followers_have_liked.append(f) print("-----------------------------Followers that havent liked a post list obtained, length: " + str(len(followers_have_not_liked))) for f in followers_have_not_liked: f.print() print("-----------------------------Followers that have liked a post list obtained, length: " + str(len(followers_have_liked))) for f in followers_have_liked: f.print() print(datetime.datetime.now()) followings_pk = get_followings(api, user_pk) f_not_liked_not_followed_y_private = [] f_not_liked_not_followed_y_public_sin_posts = [] f_not_liked_not_followed_y_public_con_posts = [] f_not_liked_not_followed_y_public_con_pocos_posts = [] x = 0 for f in followers_have_not_liked: print(str(x) + ": Assigning follower " + f.username) x += 1 if f.pk not in followings_pk: if f.private: f_not_liked_not_followed_y_private.append(f) else: if f.has_posts == "F": f_not_liked_not_followed_y_public_sin_posts.append(f) elif f.has_posts == "T": posts = get_user_posts(api, f.pk, 100) f.posts = len(posts) taken_at = posts[0]['taken_at'] f.msg = int((time.time() - taken_at)/3600/24) # seconds to days # todo ver cuando publicó por última vez o si tiene < X posts if len(posts) >= 25: f_not_liked_not_followed_y_public_con_posts.append(f) else: f_not_liked_not_followed_y_public_con_pocos_posts.append(f) print("__________f_not_liked_not_followed_y_private: " + str(len(f_not_liked_not_followed_y_private))) for f in f_not_liked_not_followed_y_private: f.print() print("__________f_not_liked_not_followed_y_public_sin_posts: " + str(len(f_not_liked_not_followed_y_public_sin_posts))) for f in f_not_liked_not_followed_y_public_sin_posts: f.print() print("__________f_not_liked_not_followed_y_public_con_posts: " + str(len(f_not_liked_not_followed_y_public_con_posts))) for f in f_not_liked_not_followed_y_public_con_posts: f.print() print("__________f_not_liked_not_followed_y_public_con_pocos_posts: " + str(len(f_not_liked_not_followed_y_public_con_pocos_posts))) for f in f_not_liked_not_followed_y_public_con_pocos_posts: f.short_print() fin = datetime.datetime.now() - inicio print("...End working.... " + str(fin)) pitar()
def main(desde=None): inicio = datetime.datetime.now() print("...Start following at ... " + inicio.strftime("%c")) api = login() user_pk = "289060797" # PK DIEGO: modificar para dar likes a otros user_pk = "364963984" # /ecto:2058288265 /themacrowizard:2211285 /joseca_lifts:904385495 /sergio.espinar:644593827 # /marcos_gt:566286300 /guillenutriscientific:828934657 /thefitmedstudent:2205196357 # /neatfitcouple:5886520324 /j.a.roa:1539017410 /sergvlc:364963984 # COntrolamos si no queremos que empiece desde cero porque estamos reanudando desde = 0 if desde is None else desde x, likes = 0, 0 api.getUsernameInfo(user_pk) username = api.LastJson['user']['username'] api.getUserFeed(user_pk) last_json = api.LastJson taken = int((time.time() - last_json['items'][0]['taken_at']) / 3600 / 24) # seconds to days post_id = last_json['items'][0]['id'] api.getMediaLikers(post_id) likers = api.LastJson likers_len = len(likers['users']) print("Following likers of user:"******", number of likes:", likers_len, ", post has", taken, "days old") file = open("followed_TEST.csv", "a") file.flush() for l in likers['users']: x += 1 try: likes += 1 api.follow(l['pk']) print(str(x) + "/" + str(likers_len) + ": " + datetime.datetime.now().strftime("%c") + " - " + str(l['username']) + ":" + str(l['pk']) + " followed!") file.write(str(x) + ";" + str(l['username']) + ";" + str(l['pk']) + ";" + "\n") file.flush() # Cada 100 descansa para evitar spammeo if (likes % 100) == 0: print("Sleeping for 300s") time.sleep(300) main(likes) _ = api.getUserFeed(l['pk']) post_id = api.LastJson['items'][0]['id'] api.like(post_id) except IndexError as err: print("index errror: ", err) except KeyError as err: print("Key error: ", err) except Exception as err: print("exception: ", err) finally: if x > desde: t = datetime.datetime.now() print("Sleeping................................... ", end="") time.sleep(random.randint(60, 70)) t2 = datetime.datetime.now() - t print("Slept for: " + str(t2)) file.flush() file.flush() file.close() fin = datetime.datetime.now() - inicio print("...End working.... " + str(likes) + " posts liked! " + str(fin)) winsound.Beep(2500, 250)