def get(self, request, uidb64, token): context = dict() uid = force_text(urlsafe_base64_decode(uidb64)) user = User.objects.filter(pk=uid).first() context['error'] = '' if not default_token_generator.check_token(user, token): context['error'] = 'invalid_token' if not context['error']: from django.http.response import HttpResponseRedirectBase HttpResponseRedirectBase.allowed_schemes += ['lulu'] redirect_url = 'lulu://password-recovery/%s/%s' % (uidb64, token) if not request.is_mobile: return render(request, 'need_redirect_to_app.html', context=context) prn('REDIRECT TO APP URL: %s' % redirect_url) return DeepLinkPageView.redirect_by_url(redirect_url) # return HttpResponseRedirect(redirect_url) return render(request, '404.html', context=context)
def __init__(self, *args, **kwargs): self._set_ref_object(FoodWebsite, **kwargs) self.scraper = self.ref_object.scraper self.scrape_url = self.ref_object.url self.scheduler_runtime = self.ref_object.scraper_runtime self.scraped_obj_class = FoodProduct self.scraped_obj_item_class = FoodProductItem # Set all products hiddes self.ref_object.product_website.update(is_hidden=True) try: super(FoodSpider, self).__init__(self, *args, **kwargs) except Exception as ex: prn(ex)
def share_photo_facebook(self, photo): prn('Sharing facebook photo') # API DOCS https://developers.facebook.com/docs/graph-api/using-graph-api/ # https: // developers.facebook.com / docs / graph - api / photo - uploads user_social = self.social_accounts[settings.FACEBOOK_PROVIDER] if not user_social: prn('Error! User have no facebook account') return False user_id = user_social.uid access_token = user_social.get_token() # SHARE_URL EXAMPLE = 'https://graph.facebook.com/{user-id}/feed?message={message}&access_token={access-token}' # user_id = 2017486768528419 # access_token = 'EAAC8rPvk6FMBAC0rkboSCPrAinDIQDgQf6beIRrxjmLKIhlnb2zOjjt2GMuHmwdKLGvojs0nqWEZC0NUN64ZC7rmSuUvkmv4vM9rS31WdizxmWjKZC0OUYD4h7YEzmZAVzAJ47wFSpRqidIOgSSXbvjGVFFv1Rv7RxeZAwclFYfauyGy6semmGZCY5fPENkcSwV7VuZCMZCkAbf0Pr1JEaCdY40zNfnjhSE72XmZBPg9XiAZDZD' # TODO PHOTO POST TEXT message = '' # photo = Photo.objects.filter(id=40).first() if photo.description: message += photo.description else: message += 'Look at my pet!' image_url = "%s%s%s" % (settings.SITE_URL, settings.MEDIA_URL, photo.image) # adding to feed # api_url = '%s%s/feed?' % (settings.FACEBOOK_API_URL, user_id) # adding to photos api_url = '%s%s/photos?' % (settings.FACEBOOK_API_URL, user_id) if self.with_debug: api_url += "&debug=all" # POST MESSAGE # response = requests.post(api_url, data={'message': message, # 'link': image_url, # 'access_token': access_token, # 'fields': 'created_time,from,id,message,permalink_url'}, json=None,) # POST PHOTO response = requests.post( api_url, data={ 'caption': message, 'url': image_url, 'access_token': access_token, 'fields': 'created_time,id,permalink_url' }, json=None, ) api_data = response.json() if response.status_code != 200: prn('Error') else: prn('No Error')
def share_photo_twitter(self, photo_todo): prn('Sharing twitter photo') # TWITTER API to tweet https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update # TODO PHOTO TEXT, need my account to delete created tweets message = 'eatbot.' api_url = 'https://api.twitter.com/1.1/statuses/update.json?status=%s' % message user_social = self.social_accounts[settings.TWITTER_PROVIDER] if not user_social: prn('Error! User have no twitter account') return False token = user_social.get_token() token_secret = user_social.get_token(need_secret=True) options = {'method': 'POST'} api_data = self.send_query_oauth2(settings.TWITTER_PROVIDER, api_url, token, token_secret, options) if 'error' in api_data: prn(api_data['error']) else: prn('Photo is tweeted')
def product_pre_save_signal(sender, instance=None, created=False, **kwargs): instance.is_hidden = False # ONLY FOR kushat podano if '<table>' in instance.description: parsed_body = html.fromstring(instance.description) all_tr = parsed_body.xpath('.//tr') count_all_tr = len(all_tr) prn(count_all_tr) cur_tr = 0 description_fixed = '<table><tbody>' for one_tr in parsed_body.xpath('.//tr'): cur_tr += 1 prn(one_tr) tr_html = etree.tostring(one_tr, pretty_print=True).decode("utf-8") prn(tr_html) if cur_tr < count_all_tr - 4: description_fixed += tr_html instance.description = description_fixed + '</tbody></table>' instance.category = instance.category.strip()
def page_404(request): prn('404') response = render(request, "404.html") response.status_code = 404 return response
def print_value(value): print('value_type = ') prn(value) return type(value)
def share_photo_pinterest(self, photo_todo): prn('Sharing pinterest photo') # PINTEREST API to post board https://developers.pinterest.com/docs/api/boards/ user_social = self.social_accounts[settings.PINTEREST_PROVIDER] if not user_social: prn('Error! User have no twitter account') return False # TODO PHOTO TEXT, need to check permission Scope: "write_public" # now error is code 3 = Authorization failed. name = 'eatbot_name' description = 'eatbot_description' token = user_social.get_token() api_url = 'https://api.pinterest.com/v1/boards/?access_token=%s' % token # 'https://api.pinterest.com/v1/me/?access_token=AXhhzU8fJ--rJNqewxPnz49GL-h1FQaM3NK05uhEmRoNmqA5xAAAAAA' options = { 'method': 'POST', 'post_parameters': { 'access_token': token, 'name': name, 'description': description } } prn(api_url) api_data = UserSocialApi.send_query_oauth2(settings.PINTEREST_PROVIDER, api_url, options=options) if 'data' in api_data and api_data['data']: prn("Board is created") else: prn('Pinterest API ERROR') prn(api_data['message'])