import twitter, argparse, sys, os import config import twert_helper parser = argparse.ArgumentParser(description="Post ebooks tweets to twitter.") parser.add_argument('-o', '--stdout', action='store_true', help="Output to stdout instead of posting to twitter.") parser.add_argument('-t', '--tweet', help="Tweet arbitrary text instead of using the brain.") args = parser.parse_args() def api(): return twitter.Api(**config.api) if args.tweet: api().PostUpdate(args.tweet) else: tweet = twert_helper.create_tweet() if args.stdout: print tweet else: status = api().PostUpdate(tweet)
else: print "Printing test replies (dry-run)" last_tweet = long(state['last_reply']) replies = None if last_tweet: replies = api.statuses.mentions_timeline(since_id=last_tweet) else: replies = api.statuses.mentions_timeline() for reply in replies: if check_names(reply): continue # try: reply_tweet = twert_helper.create_tweet(reply["text"].encode('utf-8', 'replace')).encode('utf-8', 'replace') reply_tweet = twert_helper.smart_truncate('@%s %s' % (reply["user"]["screen_name"].encode('utf-8', 'replace'), reply_tweet)) if not args.stdout: api.statuses.update(status=reply_tweet, in_reply_to_status_id=reply["id"]) else: print(reply_tweet) # except: # print 'Error posting reply.' last_tweet = max(reply["id"], last_tweet) break if not args.stdout: state['last_reply'] = str(last_tweet) print "Saving state"
last_tweet = long(state['last_reply']) replies = None if last_tweet: replies = api.statuses.mentions_timeline(since_id=last_tweet) else: replies = api.statuses.mentions_timeline() for reply in replies: if check_names(reply): continue tweet_text = reply["text"].encode('utf-8', 'replace') tweet_text = string.lstrip(tweet_text, "@" + config["screen_name"]) reply_tweet = twert_helper.create_tweet().encode('utf-8', 'replace') reply_tweet = twert_helper.smart_truncate('@%s %s' % (reply["user"]["screen_name"].encode('utf-8', 'replace'), reply_tweet)) if not args.stdout: api.statuses.update(status=reply_tweet, in_reply_to_status_id=reply["id"]) else: print(reply_tweet) # except: # print 'Error posting reply.' last_tweet = max(reply["id"], last_tweet) break if not args.stdout: state['last_reply'] = str(last_tweet) print "Saving state"
#!/usr/bin/python import twitter, argparse, sys, os import config import twert_helper reload(sys) sys.setdefaultencoding('utf-8') parser = argparse.ArgumentParser(description="Post ebooks tweets to twitter.") parser.add_argument('-o', '--stdout', action='store_true', help="Output to stdout instead of posting to twitter.") parser.add_argument('-t', '--tweet', help="Tweet arbitrary text instead of using the brain.") args = parser.parse_args() api = twitter.Api(**config.api) if args.tweet: # tweet arbitrary text from console api.PostUpdate(args.tweet) else: tweet = twert_helper.create_tweet('', not args.stdout) if tweet == unicode(''): # failure: probably couldn't generate a tweet within the alloted tries print "Could not generate a unique tweet this time" else: if(args.stdout): print "Dry run: " + tweet else: status = api.PostUpdate(tweet) print "Tweeted: " + tweet
from twitter import * parser = argparse.ArgumentParser(description="Post ebooks tweets to twitter.") parser.add_argument('-o', '--stdout', action='store_true', help="Output to stdout instead of posting to twitter.") parser.add_argument('-b', '--both', action='store_true', help="Output to stdout instead of posting to twitter.") parser.add_argument('-t', '--tweet', help="Tweet arbitrary text instead of using the brain.") args = parser.parse_args() t = Twitter(auth=OAuth(**config['api'])) if args.tweet: t.statuses.update(args.tweet) else: tweet = twert_helper.create_tweet() if args.stdout: print tweet elif args.both: print tweet status = t.statuses.update(status=tweet) else: status = t.statuses.update(status=tweet)
return False if config.replies: if not args.stdout: print "Performing replies" else: print "Printing test replies (dry-run)" last_tweet = long(state['last_reply']) replies = api.GetMentions(since_id=last_tweet) for reply in replies: if check_names(reply): continue reply_tweet = twert_helper.create_tweet(reply.text) if len(reply_tweet) == 0: # sometimes it can't be done with the catalyst given # so create something novel, instead reply_tweet = twert_helper.create_tweet() # make sure that we don't have a blank tweet # otherwise we'll send a blank reply if len(reply_tweet) > 0: reply_tweet = twert_helper.smart_truncate('@%s %s' % (reply.user.screen_name, reply_tweet)) if not args.stdout: api.PostUpdate(reply_tweet, in_reply_to_status_id=reply.id) else: print(reply_tweet) # mark it as last tweet either way