def start_bot(): while True: print '\n' print 'Hey! Welcome to instaBot!' print 'Here are your menu options:' print "a.Get your own details\n" print "b.Get details of a user by username\n" print "c.Get your own recent post\n" print "d.Get the recent post of a user by username\n" print "e.Like a post\n" print "f.Get a list of comments on the recent post of a user\n" print "g.to post a comment\n" print "h.To delete the negative comment\n" print "i. Get a list of people who have liked the recent post of a user\n" print "j.to get the user id\n" print "k.Exit" choice = raw_input("Enter you choice: ") if choice == "a": self_info() elif choice == "b": insta_username = raw_input("Enter the username of the user: "******"c": get_own_post() elif choice == "d": insta_username = raw_input("Enter the username of the user: "******"e": insta_username = raw_input("Enter the username of the user: "******"f": insta_username = raw_input("Enter the username of the user: "******"g": insta_username = raw_input("Enter the username of the user: "******"h": insta_username = raw_input("Enter the username of the user: "******"i": insta_username = raw_input("Enter the username of the user: "******"j": insta_username = insta_username = raw_input( "Enter the username of the user: "******"k": exit() else: print "wrong choice"
def menu(): while True: choice = raw_input( # jai babajiii# " 1) To get own info \n 2) To get own post \n 3) To get friends id \n 4) To get friends info \n 5) To Get friend post id \n 6) To Like post \n 7) To comment on post \n " "8) To Delete negative comments from your post\n 9) To view recent Media id like by You\n 10) To view comment of the your friends post \n 11) To find the Sub-trends of an event\n 12) To compare Pos and Neg comments of your post\n 13) To exit application\n ENTER YOUR CHOICE :- ") if choice.isdigit() == True: choice=int(choice) if choice == 1: self_info() elif choice == 2: print "Post Id : %s \n"% get_own_post() elif choice == 3: print "User ID : %s \n" % get_user_id(insta_username) elif choice == 4: get_user_info(insta_username) # Calling of get_user_info function elif choice == 5: print "Post ID : %s \n"% get_users_post(insta_username) elif choice == 6: like_a_post(insta_username) # Calling of like_a_post() function elif choice == 7: post_a_comment(insta_username) elif choice == 8: delete_negative_comment() # Calling of delete_negative_comment() function elif choice == 9: recent_media_like() # Calling of recent_media_like() function elif choice == 10: comment_list() # Calling of comment_list() function elif choice == 11: sub_trends() # Calling of sub_trends() function elif choice == 12: compare_comments() elif choice == 13: break else: print "\n\n[[what do you want to do]]"
def get_details(event=None): fname = name.get() username = user.get() bdate = date.get() if fname == '' or username == '': messagebox.showinfo('Alert!', 'Field(s) are empty !!') return if len(bdate) < 5: messagebox.showinfo('Alert!', 'Date not in correct format!!') return chk = findall(r'\d+/\d+', bdate) if chk == []: messagebox.showinfo('Alert!', 'Date not in correct format!!') return user_id = get_user_id(username) if user_id == None: messagebox.showinfo( 'Alert!', 'Username not found!!\nor Check Internet connectivity') else: #try: db, cursor = connect() query="insert into user_details values('{}','{}','{}','{}')"\ .format(user_id,username,fname,bdate) cursor.execute(query) db.commit() db.close() messagebox.showinfo('Alert!', 'Entry added to DB') name.delete(0, END) user.delete(0, END) date.delete(0, END)
def get_user_info(insta_username): #function logic user_id = get_user_id(insta_username) if user_id == None: print 'User does not exist!' exit() request_url = (BASE_URL + 'users/%s?access_token=%s') % (user_id, APP_ACCESS_TOKEN) print 'GET request url : %s' % (request_url) user_info = requests.get(request_url).json() if user_info['meta']['code'] == 200: if len(user_info['data']): print 'Username: %s' % (user_info['data']['username']) print 'No. of followers: %s' % ( user_info['data']['counts']['followed_by']) print 'No. of people you are following: %s' % ( user_info['data']['counts']['follows']) print 'No. of posts: %s' % (user_info['data']['counts']['media']) else: print 'There is no data for this user!' else: print 'Status code other than 200 received!' #get_user_info for vineet_chauhan9
def main(): #step 1: get all the id of original tutorials tutorials_id = get_id.get_id() for t_id in tutorials_id: #step 2: get all the name of original tutorials t_name = get_name.get_name(t_id) #step 3: insert id and name into org_tutorial table #database #step 4: From the result of step 3, call get_name to first level totorial info get_spinoff.get_first_spinoff(t_id) #step 5: Insert into first_level_spinoff table #database #step 6: From the result of step 5, call get_user_id to get user id user_id = get_user_id.get_user_id(t_id) #step 7: insert user info into user table #database #step 8: Call get_user_project to get all related project get_user_project.get_user_project(user_id)
def get_user_post(insta_username): # Function Logic to Download user's Recent Post.. user_id = get_user_id(insta_username) #Get the User's Id if user_id == None: print '\n\t\t*****User does not exist!*****' exit() request_url = (BASE_URL + 'users/%s/media/recent/?access_token=%s') % ( user_id, APP_ACCESS_TOKEN) print 'GET request url : %s' % (request_url) user_media = requests.get(request_url).json() if user_media['meta']['code'] == 200: #Check if there is any user or not if len(user_media['data']): image_name = user_media['data'][0]['id'] + '.jpeg' image_url = user_media['data'][0]['images']['standard_resolution'][ 'url'] (urllib.urlretrieve(image_url, image_name)) print(user_media['data'][0]['id']) print "\n\t\t*****User's Recent Post has been downloaded!*****" return user_media['data'][0]['id'] else: print '\n\t\t*****Post does not exist!*****' else: print '\n\t\t*****Status code other than 200 received!*****'
def get_comments(username): id = get_user_id(username) if id != 0: pass else: exit() post_id = get_recent_media(id) print "Fetching data..." req_url = BASE_URL + "media/" + post_id + "/comments/?access_token=" + APP_ACCESS_TOKEN comments = requests.get(req_url).json() if not comments['data']: print "No comments found." else: query = raw_input("Search for comments having certain keyword? (Leave empty if all comments): \n") if not query: for temp in comments['data']: print temp['from']['username'] + ": " + temp['text'] else: for temp in comments['data']: if temp['data']['text'].find(query) > 0: print temp['from']['username'] + ": " + temp['text'] else: pass
def get_user_info(insta_username): #FUNCTION LOGIC user_id = get_user_id(insta_username) if user_id == None: print 'User Does Not Exist' exit() request_url = (BASE_URL + 'users/%s?access_token=%s') % (user_id, APP_ACCESS_TOKEN) #print (request_url) print 'GET request url : %s' % (request_url) user_info = requests.get(request_url).json() if user_info['meta']['code'] == 200: if len(user_info['data']): print 'Username:%s' % (user_info['data']['username']) print 'No.of followers:%s' % ( user_info['data']['counts']['followed_by']) print 'No. of People you are following:%s' % ( user_info['data']['counts']['follows']) print 'No. of Posts:%s' % (user_info['data']['counts']['media']) else: print "There is no data for this user" else: print "status code other than 200 received" #get_user_info(insta_username="******")
def get_user_info(insta_username): # function logic user_id = get_user_id(insta_username) if user_id == None: print('Username does not exist') exit() request_url = (BASE_URL + 'users/%s/?access_token=%s') % (user_id, APP_ACCESS_TOKEN) print('GET request url : %s' % (request_url)) user_info = requests.get(request_url).json() if user_info['meta']['code'] == 200: if len(user_info['data']): print('\nUsername is : %s' % (user_info['data']['username'])) print('\nNumber of people who are following him are : %s' % (user_info['data']['counts']['followed_by'])) print('\nNumber of people who are followed by him are : %s' % (user_info['data']['counts']['follows'])) print('\nNumber of posts he have uploaded till now are : %s' % (user_info['data']['counts']['media'])) else: return None else: print('Status code received is other than 200') exit()
def get_user_post(insta_username): user_id = get_user_id(insta_username) if user_id == None: print"User does not Exist" exit() request_url = (BASE_URL + 'users/%s/media/recent/?access_token=%s') % (user_id, APP_ACCESS_TOKEN) print'GET request url for user post:%s' %( request_url) user_media = requests.get(request_url).json() if user_media['meta']['code'] == 200: # Here we can extract post ID if len(user_media['data']): image_name = user_media['data'][0]['id'] + '.jpeg' image_url = user_media['data'][0]['images']['standard_resolution']['url'] urllib.urlretrieve(image_url, image_name) print'Your image has been downloaded!' return user_media['data'][0]['id'] else: print'There is no recent post!' else: print"Status code other than 200 recevied!"
def get_users_post(insta_username): # function logic user_id = get_user_id(insta_username) if user_id == None: print ('Username does not exist') exit() request_url = (BASE_URL + 'users/%s/media/recent/?access_token=%s') % (user_id, APP_ACCESS_TOKEN) print ('GET request url : %s' % (request_url)) user_media = requests.get(request_url).json() if user_media['meta']['code'] == 200: # extract post id if len(user_media['data']): image_name = user_media['data'][0]['id'] + '.jpeg' image_url = user_media['data'][0]['images']['standard_resolution']['url'] urllib.urlretrieve(image_url, image_name) print ('Your image has been downloaded') return user_media['data'][0]['images']['standard_resolution']['url'] + '.jpeg' else: print ('Post does not exist') else: print user_media print ('Status code received is other than 200') exit()
def get_post_id(insta_username): user_id = get_user_id(insta_username) if user_id == None: print 'User does not exist!' exit() request_url = (BASE_URL + 'users/%s/media/recent/?access_token=%s') % (user_id, APP_ACCESS_TOKEN) print 'GET request url : %s' % (request_url) user_media = requests.get(request_url).json() if user_media['meta']['code'] == 200: if len(user_media['data']): return user_media['data'][0]['id'] else: print 'There is no recent post of the user!' exit() else: print 'Status code other than 200 received!' exit()
def get_user_info(insta_username): # Function Logic to get user profile Information user_id = get_user_id(insta_username) if user_id == None: print 'User does not exist!' exit() request_url = (BASE_URL + 'users/%s?access_token=%s') % (user_id, APP_ACCESS_TOKEN) print 'GET request url : %s\n' % (request_url) user_info = requests.get(request_url).json() if user_info['meta']['code'] == 200: if len(user_info['data']): print '\n\t\t\t****Username: %s*****' % ( user_info['data']['username']) print '\t\t\t****No. of followers: %s*****' % ( user_info['data']['counts']['followed_by']) print '\t\t\t****No. of people you are following: %s*****' % ( user_info['data']['counts']['follows']) print '\t\t\t****No. of posts: %s*****' % ( user_info['data']['counts']['media']) else: print '\n\t\t*****There is no data for this user!*****' else: print '\n\t\t*****Status code other than 200 received!*****'
def d_insert_first_level_spinoff(): # step 1: get all the id of original tutorials tutorials_id = get_id.get_id() # set up database con = mdb.connect(host="mysql1", user="******", passwd="TBtsTL4Xn6e4Whwh", db="khandb", charset="utf8") cur = con.cursor() # get all original tutorials id # cur.execute("TRUNCATE TABLE first_level_spinoff") cur.execute('SELECT org_tut_id FROM org_tutorials WHERE is_checked = "0"') results_org_tut_id = cur.fetchall() cur.execute("SELECT project_id FROM first_level_spinoff") results_project_id = cur.fetchall() for org_tut_id in results_org_tut_id: # org_tut_id = str(org_tut_id) org_tut_id = str(org_tut_id)[1:][:-3] # org_tut_id = org_tut_id # print org_tut_id results = get_spinoff.get_first_spinoff(org_tut_id) for result in results: count = 0 # database fields # 1:call get_user_id to get user id # 2:rfind('\') from url then cut it # 3:result[0]: project_title # 4:result[2]: url # 5:result[3]: parent's id project_title = result[0] url = result[2] parent_id = org_tut_id user_id = get_user_id.get_user_id(url) project_id = url[url.rfind("/") + 1 :] if not user_id: user_id = "['none']" user_id = str(user_id)[2:][:-2] for fls_project_id in results_project_id: fls_project_id = str(fls_project_id)[1:][:-3] if fls_project_id == project_id: count = 1 # print user_id # print project_id # print project_title # print url # print parent_id if count != 1: cur.execute( "INSERT INTO first_level_spinoff (user_id, project_id, project_title, url, parent_id) VALUES (%s, %s, %s, %s, %s)", (user_id, project_id, project_title, url, parent_id), ) cur.execute( 'UPDATE org_tutorials SET is_checked = "1", checked_date = current_date WHERE org_tut_id = %s', (org_tut_id) ) con.close()
def perform_sentiment_analysis(): username = get_user_username() id = get_user_id(username) if id != 0: pass else: exit() post_id = get_recent_media(id) print "Fetching data..." req_url = BASE_URL + "media/" + post_id + "/comments/?access_token=" + APP_ACCESS_TOKEN comments = requests.get(req_url).json() data = "" if not comments['data']: print "No comments found." else: for temp in comments['data']: temp['text'] += " " + temp['text'] data = temp['text'] # # SENTIMENT ANALYSIS. DO NOT MESS WITH THE CODE UNDER THIS. # blob = TextBlob(data, analyzer=NaiveBayesAnalyzer()) if blob.sentiment.classification == "neg": print "Overall negative content found. More details in the pie chart." else: print "Overall Positive content found. More details in the pie chart." print blob.sentiment.classification pos = blob.sentiment.p_pos neg = blob.sentiment.p_neg labels = 'Positive Comments %age', 'Negative Comments %age' sizes = [pos, neg] explode = (0, 0) # only "explode" the 2nd slice (i.e. 'Hogs') fig1, ax1 = plt.subplots() ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%', shadow=False, startangle=90) ax1.axis('equal' ) # Equal aspect ratio ensures that pie is drawn as a circle. plt.show()
def get_user_post(insta_username): user_id = get_user_id(insta_username) if user_id == None: print 'User does not exist!' exit() request_url = (base_url + 'users/%s/media/recent/?access_token=%s') % ( user_id, access_token) print 'GET request url : %s' % (request_url) user_media = requests.get(request_url).json() if user_media['meta']['code'] == 200: if len(user_media['data']): return user_media['data'][0]['id'] else: print "There is no recent post!" else: print "Status code other than 200 received!"
def get_parent_project_info(url): htmltext = urllib.urlopen(url).read() regex = '"origin_scratchpad": {[\s\S]*, "id": (.+?), "translated_title": "(.+?)", "slug": ' pattern = re.compile(regex) parent_project_info = re.findall(regex, htmltext) if not parent_project_info: return ["NULL", "NULL", "NULL"] else: parent_project_id = parent_project_info[0][0] parent_project_title = parent_project_info[0][1] parent_url = "https://www.khanacademy.org/cs/khan-academy/" + parent_project_id parent_user_id = str(get_user_id.get_user_id(parent_url)[0]) #print parent_url #print [parent_project_id,parent_project_title,parent_user_id] return [parent_project_id,parent_project_title,parent_user_id]
def d_insert_first_level_spinoff(): # step 1: get all the id of original tutorials tutorials_id = get_id.get_id() # set up database con = mdb.connect(host="mysql1", user="******", passwd="TBtsTL4Xn6e4Whwh", db="khandb", charset="utf8") cur = con.cursor() # get all original tutorials id # cur.execute("TRUNCATE TABLE first_level_spinoff") cur.execute('SELECT org_tut_id FROM org_tutorials WHERE is_checked = "0"') results_org_tut_id = cur.fetchall() cur.execute("SELECT project_id FROM first_level_spinoff") results_project_id = cur.fetchall() for org_tut_id in results_org_tut_id: org_tut_id = str(org_tut_id[0]) results = get_spinoff.get_first_spinoff(org_tut_id) for result in results: count = 0 project_title = result[0] url = result[2] parent_project_id = org_tut_id user_id = str(get_user_id.get_user_id(url)[0]) # user_id = str(user_id[0]) project_id = url[url.rfind("/") + 1 :] # if not user_id: # user_id = ['NULL'] for r_project_id in results_project_id: r_project_id = str(r_project_id[0]) if r_project_id == project_id: count = 1 if count != 1: cur.execute( "INSERT INTO first_level_spinoff (user_id, project_id, project_title, url, parent_project_id) VALUES (%s, %s, %s, %s, %s)", (user_id, project_id, project_title, url, parent_project_id), ) cur.execute( 'UPDATE org_tutorials SET is_checked = "1", checked_date = current_date WHERE org_tut_id = %s', (org_tut_id) ) con.close()
def get_post_id(insta_username): user_id = get_user_id(insta_username) if user_id == None: print"User does not Exist" exit() request_url = (BASE_URL + 'users/%s/media/recent/?access_token=%s') % (user_id, APP_ACCESS_TOKEN) print'GET request url for user post:%s' %( request_url) user_media = requests.get(request_url).json() if user_media['meta']['code'] == 200: # Here we can extract post ID if len(user_media['data']): return user_media['data'][0]['id'] else: print'There is no recent post!' else: print"Status code other than 200 recevied!"
def sdesk_ticket(): conf_file = os.path.expanduser('~/snowconfig.yaml') with open(conf_file, 'r') as ymlfile: cfg = yaml.load(ymlfile) auth_token = str(cfg['sdesk']['auth']) token = request.form['token'] if auth_token not in token: abort(403) slack_user = request.form['user_id'] task_for = get_user_id.get_snow_uid(get_user_id.get_user_id(slack_user)) short_desc = request.form['text'] queue = 'Service Desk' try: incident = create_incident(task_for, short_desc, queue) except IOError as err: incident = create_incident(task_for, short_desc, queue) return incident
def like_a_post(insta_username): media_id = get_user_id(insta_username) # print media_id request_url = (BASE_URL + 'media/%s/likes') % (media_id) payload = {"access_token": APP_ACCESS_TOKEN} print 'POST request url : %s' % (request_url) post_a_like = requests.post(request_url, payload).json() print post_a_like if post_a_like['meta']['code'] == 200: print "Post Liked Successfully" else: print "Unable to like post" # like_a_post('muskaansehgal1996')
def d_insert_first_level_spinoff(): #step 1: get all the id of original tutorials tutorials_id = get_id.get_id() #set up database con = mdb.connect(host="mysql1", user="******", passwd="TBtsTL4Xn6e4Whwh", db="khandb", charset='utf8'); cur = con.cursor() #get all original tutorials id cur.execute("TRUNCATE TABLE first_level_spinoff") cur.execute("SELECT org_tut_id FROM org_tutorials") results = cur.fetchall() for org_tut_id in results: #org_tut_id = str(org_tut_id) org_tut_id = str(org_tut_id)[1:][:-3] #org_tut_id = org_tut_id #print org_tut_id results = get_spinoff.get_first_spinoff(org_tut_id) for result in results: #database fields #1:call get_user_id to get user id #2:rfind('\') from url then cut it #3:result[0]: project_title #4:result[2]: url #5:result[3]: parent's id project_title = result[0] url = result[2] parent_id = org_tut_id user_id = get_user_id.get_user_id(url) project_id = url[url.rfind('/')+1:] if not user_id: user_id = "['none']" user_id = str(user_id)[2:][:-2] #print user_id #print project_id #print project_title #print url #print parent_id cur.execute("INSERT INTO first_level_spinoff (user_id, project_id, project_title, url, parent_id) VALUES (%s, %s, %s, %s, %s)", (user_id, project_id, project_title, url, parent_id)) con.close()
def get_user_post (insta_username): #FUNCTION LOGIC Here user_id = get_user_id(insta_username) if user_id == None: print 'User doesnot Exist' exit() request_url=(BASE_URL+'users/%s/media/recent/?access_token=%s') % (user_id,APP_ACCESS_TOKEN,) print 'GET request url:%s'%(request_url) user_media=requests.get(request_url).json() if user_media['meta']['code'] == 200: #EXTRACT POST ID if len(user_media['data']): image_name = user_media['data'][0]['id']+'.jpeg' image_url = user_media['data'][0]['images']['standard_resolution']['url'] urllib.urlretrieve(image_url, image_name) print "Your image Has Been Sucsessfully Downloaded!" else: print "Recently No Post Available Here" else: print 'Status code other than 200 received'
def get_post_id(insta_username): # Function Logic to show the post id user_id = get_user_id(insta_username) #Get the User's Id if user_id == None: print '\n\t\t*****User does not exist!*****' exit() request_url = (base_url + 'users/%s/media/recent/?access_token=%s') % (user_id, access_token) print 'GET request url : %s' % (request_url) user_media = requests.get(request_url).json() if user_media['meta']['code'] == 200: if len(user_media['data']): return user_media['data'][0]['id'] else: print '\n\t\t*****There is no recent post of the user!*****' exit() else: print '\n\t\t*****Status code other than 200 received!*****' exit()
def menu(): while True: choice = raw_input( " 1) To get own info \n 2) To get own post \n 3) To get friends id \n 4) To get friends info \n 5) To Get friend post id \n 6) To Like post \n 7) To comment on post \n " "8) To Delete negative comments from your post\n 9) To view recent Media id like by You\n 10) To view comment of the your friends post \n 11) To find the Sub-trends of an event\n 12) To compare Pos and Neg comments of your post\n 13) To exit application\n ENTER YOUR CHOICE :- ") if choice.isdigit() == True: choice=int(choice) if choice == 1: self_info() elif choice == 2: print "Post Id : %s \n"% get_own_post() elif choice == 3: print "User ID : %s \n" % get_user_id(insta_username) elif choice == 4: get_user_info(insta_username) # Calling of get_user_info function elif choice == 5: print "Post ID : %s \n"% get_users_post(insta_username) elif choice == 6: like_a_post(insta_username) # Calling of like_a_post() function elif choice == 7:
def like_post(username): id = get_user_id(username) if id != 0: pass else: exit() print "Which Post you want to like?" post_id = get_recent_media(id) request_url = (BASE_URL + 'media/%s/likes') % (post_id) payload = { "access_token": APP_ACCESS_TOKEN } print 'POST request url : %s' % request_url like = requests.post(request_url, payload).json() if like['meta']['code'] == 200: print 'Post liked. <3' else: print 'Cannot like post due to some error.'
def get_user_post(insta_username): user_id = get_user_id(insta_username) if user_id == None: print "user not exist" exit() url = BASE_URL + 'users/%s/media/recent/?access_token=%s' % ( user_id, APP_ACCESS_TOKEN) print "GET requested url :%s" % url req_media = requests.get(url).json() if req_media['meta']['code'] == 200: if len(req_media['data']): media_name = req_media['data'][0]['id'] + '.jpeg' media_url = req_media['data'][0]['images']['standard_resolution'][ 'url'] urllib.urlretrieve(media_url, media_name) print "image downloaded" else: print "data not found" else: print "code other than 200"
def get_hash_tag(insta_username): user_id=get_user_id(insta_username) if user_id==None: print "user not exist" exit() url=BASE_URL+'users/%s/media/recent/?access_token=%s' %(user_id,APP_ACCESS_TOKEN) print "GET requested url :%s" %url req_media=requests.get(url).json() #open a text file file=open("wordcloud_content.txt",'w') for posts in req_media['data']: #write the caption text or hashtag coments in text file in utf-8 encoding file.write(posts['caption']['text'].encode('utf-8')+' ') #close the file file.close() #call wordcloud function for making word cloud of hash tag comment in a activity wordcloud()
def get_post_id(insta_username): user_id=get_user_id(insta_username) if user_id==None: print 'user does not exist' exit() #user endpoint for getting users poat id request_url=BASE_URL+'users/%s/media/recent/?access_token=%s' %(user_id,APP_ACCESS_TOKEN) print 'Get request url %s' %request_url user_media=requests.get(request_url).json() #check if server give response to our request or not if user_media['meta']['code']==200: if len(user_media['data']): return user_media['data'][0]['id'] else: print 'there is no recent post of user' exit() else: print "code other than 200 recieved" exit()
def post_comment(username): id = get_user_id(username) if id != 0: pass else: exit() print "Which Post you want to comment on?" post_id = get_recent_media(id) text = raw_input("Type in your comment. \n") request_url = (BASE_URL + 'media/%s/comments') % (post_id) payload = { "access_token": APP_ACCESS_TOKEN, "text" : text } print 'POST request url : %s' % request_url comment = requests.post(request_url, payload).json() if comment['meta']['code'] == 200: print 'You commented on post' else: print 'Something went wrong.'
def insert_org_tut_spinoff(): #set up database con = mdb.connect(host="mysql1", user="******", passwd="TBtsTL4Xn6e4Whwh", db="khandb", charset='utf8'); cur = con.cursor() cur.execute('SELECT org_tut_id, spinoff_count FROM 0810_0_original_tutorial WHERE is_checked = "0"') db_org_tuts = cur.fetchall() cur.execute('SELECT project_id FROM 0810_first_level_spinoff') db_project_ids = cur.fetchall() for db_org_tut in db_org_tuts: parent_project_id = db_org_tut[0] spinoff_count = db_org_tut[1] print parent_project_id if spinoff_count <= 2000 : org_tut_spinoff_urls = gasu.get_all_spinoff_url(parent_project_id, spinoff_count) else: org_tut_spinoff_urls = gasub2.get_all_spinoff_url_bigger_2k(parent_project_id, spinoff_count) accurate_spinoff_count = len(org_tut_spinoff_urls) for org_tut_spinoff_url in org_tut_spinoff_urls: user_id = gui.get_user_id(org_tut_spinoff_url) project_id = org_tut_spinoff_url[org_tut_spinoff_url.rfind("/")+1:] if not is_in_db(db_project_ids, project_id): org_tut_spinoff_info = gpi.get_project_info(project_id) title = org_tut_spinoff_info[0] created_date = org_tut_spinoff_info[4].replace("T"," ").replace("Z","") spinoff_count = org_tut_spinoff_info[5] parent_project_id = org_tut_spinoff_info[6] #print project_id cur.execute("INSERT INTO 0810_first_level_spinoff (user_id, project_id, project_title, url, created, spinoff_count, parent_project_id, org_tut_id, inserted_time) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, now())", (user_id[0], project_id, title, org_tut_spinoff_url, created_date, spinoff_count, parent_project_id, parent_project_id)) cur.execute('UPDATE 0810_0_original_tutorial SET is_checked = "1", checked_date = now(), a_spinoff_count = %s WHERE org_tut_id = %s', (accurate_spinoff_count, parent_project_id)) con.close()
def get_user_info(insta_username): # Defination of function get_user_info user_id = get_user_id(insta_username) # Calling of get_user_id() function if user_id == None: # Checking response of get_user_id() function print 'User does not exist! \n' else: request_url = (BASE_URL + 'users/%s?access_token=%s') % ( user_id, APP_ACCESS_TOKEN) # Making request URL print 'GET request url : %s' % (request_url) user_info = requests.get(request_url).json( ) # Making request to server and storing response in json format if user_info['meta']['code'] == 200: # Checking response from server if len(user_info['data']): print "Username is : %s" % (user_info['data']['username']) print "Number of Posts : %s" % ( user_info['data']['counts']['media']) print "Followed by : %s" % ( user_info['data']['counts']['followed_by']) print "Follows : %s" % (user_info['data']['counts']['follows']) else: print "user does not exist \n" else: print "Status code other than 200 received \n"
def get_users_post(insta_username): #function logic user_id = get_user_id(insta_username) if user_id == None: print 'User does not exist!' exit() request_url = (BASE_URL + 'users/%s/media/recent/?access_token=%s') % (user_id, APP_ACCESS_TOKEN) print 'GET request url for user post : %s' % (request_url) user_media = requests.get(request_url).json() if user_media['meta']['code'] == 200: # extract post ID if len(user_media['data']): image_name = user_media['data'][0]['id'] + '.jpeg' image_url = user_media['data'][0]['images']['standard_resolution']['url'] urllib.urlretrieve(image_url, image_name) print user_media['data'][0]['id'] return user_media['data'][0]['id'] else: print "There is no recent post!" else: print 'Status code other than 200 received!'
def get_post_id(insta_username): user_id = get_user_id(insta_username) if user_id == None: print('Username does not exist') exit() request_url = (BASE_URL + 'users/%s/media/recent/?access_token=%s') % ( user_id, APP_ACCESS_TOKEN) print('GET request url : %s' % (request_url)) user_media = requests.get(request_url).json() if user_media['meta']['code'] == 200: # extract post id if len(user_media['data']): return user_media['data'][0]['id'] else: print('Post does not exist') else: print(user_media) print('Status code received is other than 200') exit()
def get_user_info(insta_username): #function logic here user_id = get_user_id(insta_username) if user_id == None: print 'User does not exist!' exit() else: print 'successfully' show== menu_choice request_url = (BASE_URL + 'users/%s?access_token=%s') % (user_id, APP_ACCESS_TOKEN) user_info = requests.get(request_url).json() if user_info['meta']['code'] == 200: if len(user_info['data']): print '\nUsername: %s' % (user_info['data']['username']) print '\nNo. of followers: %s' % (user_info['data']['counts']['followed_by']) print '\nNo. of people you are following: %s' % (user_info['data']['counts']['follows']) print '\nNo. of posts: %s' % (user_info['data']['counts']['media']) else: print Fore.RED+Style.BRIGHT+'There is no data for this user!' else: print Fore.RED+Style.BRIGHT+'Status code other than 200 received!' #get_user_info(insta_username="******")
self_info() elif choice == "2": insta_username = raw_input("Enter the username of the user: "******"3": get_own_post() elif choice == "4": insta_username = raw_input("Enter the username of the user: "******"5": insta_username = raw_input("Enter the username of the user: "******"6": insta_username = raw_input("Enter the username of the user: "******"7": insta_username = raw_input("Enter the username of the user: "******"8": insta_username = raw_input("Enter the username of the user: "******"9": insta_username = raw_input("Enter the user name: ") delete_negative_comment(insta_username) elif choice == "10": insta_username = raw_input("Enter the user name: ") analyse_user(get_user_id(insta_username)) elif choice == "11": exit() else: print "Your choose wrong choice plz choose again......."