Example #1
0
def generate_device_id():
  from google.appengine.ext import ndb
  identifier = int(ndb.Model.allocate_ids(size=1)[0])
  from shortener import encode
  return encode(identifier)
Example #2
0
    def add(cls, story):
        story_id_int = story.get('id')
        story_id = str(story_id_int)
        short_id = shortener.encode(story_id_int)
        hn_url = "https://news.ycombinator.com/item?id={}".format(story_id)
        story_url = story.get('url')

        # Check memcache and databse, maybe this story was already sent
        if memcache.get(story_id):
            logging.info('STOP: {} in memcache'.format(story_id))
            return
        post = ndb.Key(cls, story_id).get()
        if post:
            logging.info('STOP: {} in DB'.format(story_id))
            post.add_memcache()
            return
        logging.info('SEND: {}'.format(story_id))

        story['title'] = story.get('title').encode('utf-8')
        comments_count = story.get('descendants', 0)
        buttons = []

        if development():
            short_hn_url = 'http://*****:*****@hacker_news_500', message,
                                  {'inline_keyboard': [buttons]})
        else:
            result = send_message(CHANNEL_NAME, message,
                                  {'inline_keyboard': [buttons]})

        logging.info('Telegram response: {}'.format(result))

        telegram_message_id = None
        if result and result.get('ok'):
            telegram_message_id = result.get('result').get('message_id')
        post = cls(id=story_id,
                   title=story.get('title'),
                   url=story.get('url'),
                   score=story.get('score'),
                   text=story.get('text'),
                   short_url=short_url,
                   short_hn_url=short_hn_url,
                   message=message,
                   telegram_message_id=telegram_message_id)
        post.put()
        post.add_memcache()
Example #3
0
  def add(cls, story):
    story_id_int = story.get('id')
    story_id = str(story_id_int)
    short_id = shortener.encode(story_id_int)
    hn_url = "https://news.ycombinator.com/item?id={}".format(story_id)
    story_url = story.get('url')

    # Check memcache and databse, maybe this story was already sent
    if memcache.get(story_id):
      logging.info('STOP: {} in memcache'.format(story_id))
      return
    post = ndb.Key(cls, story_id).get()
    if post:
      logging.info('STOP: {} in DB'.format(story_id))
      post.add_memcache()
      return
    logging.info('SEND: {}'.format(story_id))

    story['title'] = story.get('title').encode('utf-8')
    comments_count = story.get('descendants', 0)
    buttons = []

    if development():
      short_hn_url = 'http://*****:*****@hacker_news_feed_st', message,
                            {'inline_keyboard': [buttons]})
    else:
      result = send_message('@hacker_news_feed', message,
                            {'inline_keyboard': [buttons]})

    logging.info('Telegram response: {}'.format(result))

    telegram_message_id = None
    if result and result.get('ok'):
      telegram_message_id = result.get('result').get('message_id')
    post = cls(id=story_id, title=story.get('title'), url=story.get('url'),
               score=story.get('score'), text=story.get('text'),
               short_url=short_url, short_hn_url=short_hn_url,
               message=message, telegram_message_id=telegram_message_id)
    post.put()
    post.add_memcache()
Example #4
0
    def add(cls, story):
        story_id = story.get('id')
        story_id_int = int(story_id)
        short_id = shortener.encode(story_id_int)
        dn_url = "https://www.designernews.co/stories/{}".format(story_id)
        story_url = story.get('url')

        # Check memcache and database, maybe this story was already sent
        if memcache.get(story_id):
            logging.info('STOP: {} in memcache'.format(story_id))
            return
        post = ndb.Key(cls, story_id).get()
        if post:
            logging.info('STOP: {} in DB'.format(story_id))
            post.add_memcache()
            return
        logging.info('SEND: {}'.format(story_id))

        story['title'] = story.get('title').encode('utf-8')
        comments_count = story.get('comment_count', 0)
        buttons = []

        if development():
            short_dn_url = 'http://*****:*****@designer_news_st', message,
                                  {'inline_keyboard': [buttons]})
        else:
            result = send_message('@designer_news', message,
                                  {'inline_keyboard': [buttons]})

        logging.info('Telegram response: {}'.format(result))

        telegram_message_id = None
        if result and result.get('ok'):
            telegram_message_id = result.get('result').get('message_id')
        post = cls(id=story_id,
                   title=story.get('title'),
                   url=story.get('url'),
                   score=story.get('vote_count'),
                   text=story.get('comment'),
                   short_url=short_url,
                   short_dn_url=short_dn_url,
                   message=message,
                   telegram_message_id=telegram_message_id)
        post.put()
        post.add_memcache()
Example #5
0
    def add(cls, shot):
        shot_id = shot.get('id')
        short_id = shortener.encode(shot_id)
        shot_url = shot.get('url')

        # Check memcache and database, maybe this shot was already sent
        if memcache.get('d/{}'.format(shot_id)):
            logging.info('STOP: {} in memcache'.format(shot_id))
            return
        post = ndb.Key(cls, shot_id).get()
        if post:
            logging.info('STOP: {} in DB'.format(shot_id))
            post.add_memcache()
            return
        logging.info('SEND: {}'.format(shot_id))

        shot['title'] = shot.get('title').encode('utf-8')
        # comments_count = shot.get('comments', 0)
        votes_count = shot.get('likes', 0)

        if development():
            short_url = 'http://*****:*****@designer_news_st', shot.get('video'),
                                    message, {'inline_keyboard': [buttons]})
            else:
                result = send_photo('@designer_news_st', shot.get('img'),
                                    message, {'inline_keyboard': [buttons]})

        else:
            if shot.get('video'):
                result = send_video('@designer_news', shot.get('video'),
                                    message, {'inline_keyboard': [buttons]})
            else:
                result = send_photo('@designer_news', shot.get('img'), message,
                                    {'inline_keyboard': [buttons]})

        logging.info('Telegram response: {}'.format(result))

        telegram_message_id = None
        if result and result.get('ok'):
            telegram_message_id = result.get('result').get('message_id')
        post = cls(id=shot_id,
                   title=shot.get('title'),
                   url=shot_url,
                   score=votes_count,
                   short_url=short_url,
                   message=message,
                   telegram_message_id=telegram_message_id)
        post.put()
        post.add_memcache()
Example #6
0
    def add(cls, project):
        project_id = project.get('id')
        project_id_int = int(project_id)
        short_id = shortener.encode(project_id_int)
        project_url = project.get('url')

        # Check memcache and database, maybe this project was already sent
        if memcache.get('b/{}'.format(project_id)):
            logging.info('STOP: {} in memcache'.format(project_id))
            return
        post = ndb.Key(cls, project_id).get()
        if post:
            logging.info('STOP: {} in DB'.format(project_id))
            post.add_memcache()
            return
        logging.info('SEND: {}'.format(project_id))

        project['name'] = project.get('name').encode('utf-8')
        stats = project.get('stats', {})
        comments_count = stats.get('comments', 0)
        votes_count = stats.get('appreciations', 0)

        if development():
            short_url = 'http://*****:*****@designer_news_st',
                                project.get('covers').get('original'), message,
                                {'inline_keyboard': [buttons]})

        else:
            result = send_photo('@designer_news',
                                project.get('covers').get('original'), message,
                                {'inline_keyboard': [buttons]})

        logging.info('Telegram response: {}'.format(result))

        telegram_message_id = None
        if result and result.get('ok'):
            telegram_message_id = result.get('result').get('message_id')
        post = cls(id=project_id,
                   title=project.get('name'),
                   url=project_url,
                   score=votes_count,
                   short_url=short_url,
                   message=message,
                   telegram_message_id=telegram_message_id)
        post.put()
        post.add_memcache()