def _test_url(self): args=[u'*****@*****.**', u'file%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4'] url = RequestUtils.getUrl(args) self.assertEquals(False,RequestUtils.checkUrl(url)); args=[u'*****@*****.**', u'chrome%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4'] url = RequestUtils.getUrl(args) self.assertEquals(False,RequestUtils.checkUrl(url)); args=[u'*****@*****.**', u'about%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4'] url = RequestUtils.getUrl(args) self.assertEquals(False,RequestUtils.checkUrl(url)); args=[u'*****@*****.**', u'ed2k%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4'] url = RequestUtils.getUrl(args) self.assertEquals(False,RequestUtils.checkUrl(url)); args=[u'*****@*****.**', u'liberator%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4'] url = RequestUtils.getUrl(args) self.assertEquals(False,RequestUtils.checkUrl(url)); args=[u'*****@*****.**', u'irc%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4'] url = RequestUtils.getUrl(args) self.assertEquals(False,RequestUtils.checkUrl(url)); args=[u'*****@*****.**', u'chrome-extension%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4'] url = RequestUtils.getUrl(args) self.assertEquals(False,RequestUtils.checkUrl(url)); args=[u'*****@*****.**', u'http%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4'] url = RequestUtils.getUrl(args) self.assertEquals(True,RequestUtils.checkUrl(url));
def post(self): ud, args = RequestUtils.parse_request(self.request.body) logging.info('Received args:%s' % args) client = RequestUtils.getClient(args) user=RequestUtils.getUser(ud,args) url=RequestUtils.getUrl(args) domain=RequestUtils.getDomain(url) title = RequestUtils.getTitle(args, client) version = RequestUtils.getVersion(args) selection = RequestUtils.getSelection(args) share_mode = RequestUtils.getShareMode(args) if not RequestUtils.checkUrl(url): logging.info('skipping since url is not good!') self.response.out.write('{"message":"Bad url"}') return user_agent = self.request.headers['User-agent'] if user is None or len(user) == 0: logging.info('skipping since user is not defined ( client %s )' % client ) from google.appengine.api import mail if ENVIRONMENT == 'http://www.instaright.com': mail.send_mail(sender='*****@*****.**', to='*****@*****.**', subject='Bad request!', html='Request: args = %s <br> ud: %s' %( args, ud), body='Request: args = %s <br> ud: %s' %( args, ud)) self.response.out.write('{"message":"User not defined"}') return logging.info('request has been made from valid user %s' % user) try: taskqueue.add(queue_name='link-queue', url='/article/task', params={'user': user, 'url': url, 'domain': domain, 'title': title, 'version': version,'client': client, 'selection': selection, 'user_agent': user_agent, 'share_mode': share_mode}) except TransientError: taskqueue.add(queue_name='link-queue', url='/article/task', params={'user': user, 'url': url, 'domain': domain, 'title': title, 'version': version,'client': client, 'selection': selection, 'user_agent': user_agent, 'share_mode': share_mode}) if client == 'bookmarklet': logging.info('bookmarklet specific response') self.response.out.write('{"close_html":"Link successfully marked"}') return cachedBadge = memcache.get('badge_'+user) logging.info('looking for badge %s' % 'badge_'+user) if cachedBadge is not None: logging.info('response badge %s' %cachedBadge) self.response.out.write(cachedBadge) else: logging.info('no badge found, using default') self.response.out.write('')
def post(self): user=self.request.get('user',None) user=urllib.unquote(user) url=self.request.get('url',None) domain=self.request.get('domain',None) title=self.request.get('title',None) share_mode=self.request.get('share_mode',None) if not RequestUtils.checkUrl(url): logging.info('skipping since url is not good!') return lu = LinkUtils() link_info = lu.getLinkInfo(url) description = link_info["d"] embeded = link_info["e"] logging.info('got post title %s' % title) title_new = link_info["t"] if title is None and title_new is not None and len(title_new) > 0: title = title_new if title is None or title == 'None' or title == 'null': title=LinkUtils.getLinkTitle(url) if title is not None: title = title[:199] logging.info('final link title %s' %title) logging.info("link info desc: %s embede: %s" %( description, embeded)) version=self.request.get('version',None) client=self.request.get('client',None) selection = self.request.get('selection', None) user_agent = self.request.get('user_agent',None) UserScoreUtility.updateLinkScore(user,url) UserScoreUtility.updateDomainScore(user, domain) taskqueue.add(url='/user/badge/task', queue_name='badge-queue', params={'url':url, 'domain':domain, 'user':user, 'version': version, 'client': client}) taskqueue.add(url='/link/traction/task', queue_name='link-queue', params={'url':url, 'user': user, 'title': title}) taskqueue.add(url='/link/recommendation/task', queue_name='default', params={'url':url }) name = "url" generic_counter.increment(name) url_cnt = generic_counter.get_count(name) logging.info("total url count %s " % url_cnt) e = EncodeUtils() enbased=e.encode(url_cnt) url_encode26 = e.enbase(enbased) logging.info("url encode: %s and enbase : %s" % (enbased, url_encode26)) url_hash = LinkUtils.getUrlHash(url) today = datetime.datetime.now().date() model = SessionModel.gql('WHERE instaright_account = :1 and url_hash = :2 and date > :3', user, url_hash, today).get() new_entity=False if model is None: logging.info('did not find save dafined by: %s %s for date %s', user, url, str(today)) model = SessionModel() new_entity=True else: logging.info('existing url(key %s) updating certain params' %str(model.key())) logging.info('link: %s title: %s' %(url, title)) try: #remove for local testing model.ip = self.request.remote_addr model.instaright_account = user model.date = datetime.datetime.now() if new_entity == True: model.url = url model.url_hash = url_hash model.url_counter_id = url_cnt model.url_encode26 = url_encode26 model.title = title model.user_agent=user_agent model.domain = domain model.short_link = None model.feed_link = None model.version = version model.client = client model.selection = selection model.embeded = embeded while True: timeout_ms= 100 try: model.put() break except datastore_errors.Timeout: logging.info('model save timeout retrying in %s' % timeout_ms) time.sleep(timeout_ms) timeout_ms *= 2 logging.info('send link : url_hash %s title %s user_id %s updated %s client: %s' %(model.url_hash, model.title, str(model.key()), str(model.date), model.client)) except BadValueError, apiproxy_errors.DeadlineExceededError: e0, e1 = sys.exc_info()[0], sys.exc_info()[1] logging.error('error while saving url %s ( %s, %s)' % (url, e0, e1))