Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def post(self, request, *args, **kwargs):
- username = request.POST.get('username')
- password = request.POST.get('pass')
- api_user = InstagramAPI(username=username, password=password)
- api_user.login()
- if not api_user.isLoggedIn:
- message = json.loads(api_user.LastResponse.text)['message']
- messages.error(request, message)
- return render(request, self.template_name, {})
- else:
- if not User.objects.filter(username=api_user.username).exists():
- User.objects.create_user(username=api_user.username, password=password)
- auth_user = authenticate(username=api_user.username, password=password)
- login(request, auth_user)
- return redirect('core:home')
- # api_user.getSelfUsernameInfo()
- # picture = api_user.LastJson['user']['profile_pic_url']
- # rate = self.get_social_rete(api_user)
- # return render(request, 'personal_page.html', {'pic': picture, 'rate': rate})
- def get_social_rete(self, api_obj):
- DEFAULT_DATE_FORMAT = "%Y-%m-%d"
- date_today = date.today()
- date_x = date_today - timedelta(days=90)
- date_x = date_x.strftime(DEFAULT_DATE_FORMAT)
- timestamp_date = int(parser.parse(date_x).timestamp())
- api_obj.getSelfUserFollowers()
- set_followers = {i['username'] for i in api_obj.LastJson['users']}
- api_obj.getSelfUsersFollowing()
- set_following = {i['username'] for i in api_obj.LastJson['users']}
- api_obj.getSelfUserFeed(minTimestamp=timestamp_date)
- list_media_id = [i['pk'] for i in api_obj.LastJson['items']]
- n = len(list_media_id)
- bidirectional_connection = set_following & set_followers
- author_sub_user_not = set_following - bidirectional_connection
- user_sub_author_not = set_followers - bidirectional_connection
- total_A = 0
- total_B = 0
- total_C = 0
- total_D = 0
- for pk in list_media_id:
- api_obj.getMediaLikers(pk)
- list_likes_users = [i['username'] for i in api_obj.LastJson['users'] if i['username'] != api_obj.username]
- for i in list_likes_users:
- if i in bidirectional_connection:
- total_A += 1
- elif i in author_sub_user_not:
- total_B += 1
- elif i in user_sub_author_not:
- total_C += 1
- else:
- total_D += 1
- total_E = 0
- total_F = 0
- total_G = 0
- total_H = 0
- for pk in list_media_id:
- api_obj.getMediaComments(str(pk))
- list_comments_users = [i['user']['username'] for i in api_obj.LastJson['comments'] if
- i['user']['username'] != api_obj.username]
- for i in list_comments_users:
- if i in bidirectional_connection:
- total_E += 1
- elif i in author_sub_user_not:
- total_F += 1
- elif i in user_sub_author_not:
- total_G += 1
- else:
- total_H += 1
- A = 1
- B = 0.7
- C = 0.3
- D = 0.1
- E = 0.5
- F = 0.35
- G = 0.15
- H = 0.05
- try:
- res = (
- A * total_A +
- B * total_B +
- C * total_C +
- D * total_D +
- E * total_E +
- F * total_F +
- G * total_G +
- H * total_H) / n
- except ZeroDivisionError:
- res = 0
- res = res if res >= 5 else 0
- return res
Add Comment
Please, Sign In to add comment