def test_user_linked_before(self):
       self.assertFalse(UserLinkRecord.has_linked_before('abc', '123'))
       self.assertTrue(UserLinkRecord.has_linked_before('abc', '123'))

       # same user can link to other stuff
       self.assertFalse(UserLinkRecord.has_linked_before('abcd', '123'))

       # different users can link to same stuff
       self.assertFalse(UserLinkRecord.has_linked_before('abc', '1234'))
       ttl = rc.conn.ttl('UL:abc:1234') 

       # link should have been set up to expire
       self.assertTrue(isinstance(ttl, long))
       self.assertTrue(ttl <= DOUBLE_LINK_EXCLUSION_TIME)
Exemple #2
0
    def status(self, json_obj):
        try:
            user_id = json_obj['user']['id_str']
            for url_info in json_obj['entities']['urls']:
                url = url_info['expanded_url']
                vimeo_id = vimeo_id_from_url(url)
                if not vimeo_id:
                    print 'No vid link %s' % url
                    continue
                LINK_COUNT.increment()
                if UserLinkRecord.has_linked_before(vimeo_id, user_id):
                    print 'multiple links by %s to %s' % (user_id, url)
                    continue

                timezone = json_obj['user']['time_zone']
                lang = json_obj['user']['lang']
                text = json_obj['text']
                if english_speaking(timezone, lang, text):
                    maybe_fetch_metadata(vimeo_id)
                    HourSet(ENGLISH_LINKS).increment(vimeo_id)
                    maybe_store_tweet(vimeo_id, json_obj)
                else:
                    HourSet(NON_ENGLISH_LINKS).increment(vimeo_id)

        except Exception,e :
            print e