Commit 6c3c1cd9 authored by velayat's avatar velayat
Browse files

add python script to get data

parent 65edba38
import instaloader
import pymongo
from datetime import timezone
L = instaloader.Instaloader()
L.login('shahriarvelayat', 'shve8864@@')
post = instaloader.Post.from_shortcode(L.context, 'CRWNkkchs2x')
client = pymongo.MongoClient(
"*******************************************")
db = client["instagram-lottry"]
col = db["comments"]
comments_from_loop_including_answers = []
for comment in post.get_comments():
print("Searching : ", comment.id)
search = col.find_one({"comment_id": comment.id})
try:
if search is not None and search["comment_id"]:
print(comment.id, " Already Exist")
else:
temp = {"comment_id": comment.id, "owner_username": comment.owner.username,
"owner_id": comment.owner.userid,
"text": comment.text, "date": comment.created_at_utc.timestamp()}
x = col.update(temp, temp, upsert=True)
print(comment.id, " added")
except:
print("")
# x = col.insert_one({"comment_id":comment.id ,"owner_username" : comment.owner.username ,
# "owner_id":comment.owner.userid, "text":comment.text , "date" : comment.created_at_utc.timestamp() })
# comments_from_loop_including_answers.append(comment)
print(len(comments_from_loop_including_answers))
username = "shahriarvelayat"
password = "pj!GorO!0oWo$t6f"
mongo_connection_string = "mongodb://azadi:azadi%404010@185.231.180.248:27017/?serverSelectionTimeoutMS=5000&connectTimeoutMS=10000&authSource=admin&authMechanism=SCRAM-SHA-256"
database_name = "azadi-gold-backend"
post_short_code = "CSCUev0swJO"
PROFILE = "azadi.gold"
def __main__():
print("connecting to the instagram ....")
L = instaloader.Instaloader()
L.login(username, password)
profile = instaloader.Profile.from_username(L.context, PROFILE)
print("connected to the instagram :) ")
print("Load post data ....")
post = instaloader.Post.from_shortcode(L.context, post_short_code)
print("Post data loaded :) ")
print("connecting to the database ....")
client = pymongo.MongoClient(mongo_connection_string)
db = client[database_name]
# get likes of given post short code
getLikes(db, post);
# get comments of given post short code
getComments(db, post);
# get Followers of given profile
getFollowers(db, profile);
# get tagged Posts of given profile
getTaggedPosts(db, profile);
def getComments(db, post):
col = db["comments"]
for comment in post.get_comments():
print("Searching : ", comment.id)
search = col.find_one({"comment_id": comment.id})
try:
if search is not None and search["comment_id"]:
print(comment.id, " Already Exist")
else:
temp = {"comment_id": comment.id, "owner_username": comment.owner.username,
"owner_id": comment.owner.userid,
"text": comment.text, "date": comment.created_at_utc.timestamp()}
x = col.update(temp, temp, upsert=True)
print(comment.id, " added")
except:
print("Error")
def getLikes(db, post):
col = db["likes"]
for like in post.get_likes():
print("Searching : ", like.username, post_short_code)
search = col.find_one({"username": like.username, "post_short_code": post_short_code})
try:
if search is not None:
print(like.username, " Already like post : ", post_short_code)
else:
temp = {"username": like.username, "post_short_code": post_short_code}
x = col.update(temp, temp, upsert=True)
print(like.username, " like post : ", post_short_code)
except:
print("Error")
def getFollowers(db, profile):
col = db["followers"]
for follower in profile.get_followers():
print("Searching in ", profile, " for :", follower.username)
search = col.find_one({"username": follower.username})
try:
if search is not None:
print(follower.username, " Already Exist in : ", profile, "Followers")
else:
temp = {"username": follower.username, "user_id": follower.userid, "full_name": follower.full_name,
"business_username": PROFILE, "follow_date": "", "profile_pic": follower.profile_pic_url, }
x = col.update(temp, temp, upsert=True)
print(follower.username, " followed : ", profile)
except:
print("Error")
def getTaggedPosts(db, profile):
col = db["tagged"]
for tagged_post in profile.get_tagged_posts():
print("Searching in ", profile, " for tagged post with id :", tagged_post.shortcode)
search = col.find_one({"short_code": tagged_post.shortcode})
try:
if search is not None:
print(tagged_post.shortcode, " Already Exist in : tagged_posts")
else:
temp = {"username": tagged_post.username, "user_id": tagged_post.userid,
"post_short_code": tagged_post.shortcode,
"business_username": PROFILE, "post_date": tagged_post.date_utc}
x = col.update(temp, temp, upsert=True)
print(tagged_post.shortcode, " added")
except:
print("Error")
__main__();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment