Пример #1
0
def comments_redirect(short_id):
    """Redirect to comments url"""
    try:
        story_id = str(shortener.decode(short_id))
    except:
        return abort(400)
    hn_url = "https://news.ycombinator.com/item?id={}".format(story_id)
    return redirect(hn_url)
Пример #2
0
def comments_redirect(short_id):
  """Redirect to comments url"""
  try:
    story_id = str(shortener.decode(short_id))
  except:
    return abort(400)
  hn_url = "https://news.ycombinator.com/item?id={}".format(story_id)
  return redirect(hn_url)
Пример #3
0
def story_redirect(short_id):
  """Redirect to story url"""
  try:
    story_id = str(shortener.decode(short_id))
  except:
    return abort(400)
  redirect_url = memcache.get(story_id)
  if not redirect_url:
    story = ndb.Key(StoryPost, story_id).get()
    if not story:
      return make_response('<h1>Service Unavailable</h1><p>Try again later</p>', 503, {'Retry-After': 5})
    story.add_memcache()
    redirect_url = story.url
  return redirect(redirect_url)
Пример #4
0
def story_redirect(short_id):
  """Redirect to story url"""
  try:
    story_id = str(shortener.decode(short_id))
  except:
    return abort(400)
  redirect_url = memcache.get(story_id)
  if not redirect_url:
    story = ndb.Key(StoryPost, story_id).get()
    if not story:
      return make_response('<h1>Service Unavailable</h1><p>Try again later</p>', 503, {'Retry-After': 5})
    story.add_memcache()
    redirect_url = story.url
  return redirect(redirect_url)
Пример #5
0
def resolve(url):
    long_url = shortener.decode(url)
    if (long_url):
        long_url = long_url.replace('"', '')
        if ("http://" not in long_url):
            if ("https://" not in long_url):
                long_url = "http://" + long_url
            # else:
            # 	long_url="http://"+long_url

        print(long_url)
        return redirect(long_url)
    else:
        return "Wrong Link!"