Beispiel #1
0
from update_dataset import update_dataset

capitalize = os.environ.get("EBOOKS_CAPITALIZE", False) != False
interval   = int(os.environ.get("EBOOKS_INTERVAL", "14400"))
username   = os.environ["EBOOKS_USERNAME"]
target     = os.environ["EBOOKS_TARGET"]
hashtag    = os.environ.get("EBOOKS_HASHTAG", "")

auth = json.loads(os.environ["EBOOKS_AUTH"])
_auth = tweepy.OAuthHandler(auth['consumer_key'], auth['consumer_secret'])
_auth.set_access_token(auth['access_token_key'], auth['access_token_secret'])
api = tweepy.API(_auth)

if os.environ.has_key("REDISTOGO_URL"):
    urlparse.uses_netloc.append("redis")
    url = urlparse.urlparse(os.environ["REDISTOGO_URL"])
    db = redis.Redis(host=url.hostname, port=url.port, db=0, password=url.password)
else:
    db = redis.Redis()

while "they're taking the hobbits to Isengard":
    update = update_dataset(username, auth, db.get("last_id"))
    if update:
        (data, last_id) = update
        db.append("data", data)
        db.set("last_id", last_id)
    gen = Generator(db.get("data"), capitalize, hashtag)
    tweet = gen.tweetworthy()
    api.update_status(tweet)
    time.sleep(interval)
Beispiel #2
0
capitalize = os.environ.get("EBOOKS_CAPITALIZE", False) != False
interval = int(os.environ.get("EBOOKS_INTERVAL", "14400"))
username = os.environ["EBOOKS_USERNAME"]
target = os.environ["EBOOKS_TARGET"]

auth = json.loads(os.environ["EBOOKS_AUTH"])
_auth = tweepy.OAuthHandler(auth['consumer_key'], auth['consumer_secret'])
_auth.set_access_token(auth['access_token_key'], auth['access_token_secret'])
api = tweepy.API(_auth)

if os.environ.has_key("REDISTOGO_URL"):
    urlparse.uses_netloc.append("redis")
    url = urlparse.urlparse(os.environ["REDISTOGO_URL"])
    db = redis.Redis(host=url.hostname,
                     port=url.port,
                     db=0,
                     password=url.password)
else:
    db = redis.Redis()

while "they're taking the hobbits to Isengard":
    update = update_dataset(username, auth, db.get("last_id"))
    if update:
        (data, last_id) = update
        db.append("data", data)
        db.set("last_id", last_id)
    gen = Generator(db.get("data"), capitalize)
    tweet = gen.tweetworthy()
    api.update_status(tweet)
    time.sleep(interval)
        # Remove mismatched enclosures
        for pair in [['(', ')'], ['{', '}'], ['[', ']']]:
            if product.count(pair[0]) != product.count(pair[1]):
                product = product.replace(pair[0], '').replace(pair[1], '')

        for enc in ['"', '*']:
            if product.count(enc) % 2 != 0:
                product = product.replace(enc, '')

        return product


if __name__ == '__main__':
    if len(sys.argv) < 2:
        print "Usage: %s @parody_account" % sys.argv[0]
        sys.exit()

    username = sys.argv[1]
    target = SETTINGS[username]['target'].replace('@','')

    if not os.path.exists(os.path.join(TOPDIR, 'users', target, 'tweets')):
        from update_dataset import update_dataset
        update_dataset(target)

    gen = Generator(target, SETTINGS[username])
    tweet = gen.tweetworthy()
    print tweet

    api = twitter.Api(**SETTINGS[username]['auth'])
    api.PostUpdate(tweet)