def produce_next_tweet(app_status): app_status = status.load() # Just get the latest tweets tweets = twitter.get_timeline_tweets(800) tweets = filter_tweets(tweets) tweets = filter(lambda t:not t['user']['screen_name'] == twitter_settings.screen_name, tweets) if len(tweets) <= 1: print('Could not generate tweet (not enough eligible tweets)') app_status['latest_tweet'] = 'Could not generate tweet (not enough eligible tweets)' return recent_tweets = twitter.get_tweets(twitter_settings.screen_name, True) best_tweet = create_markovated_tweet(tweets, 140, map(lambda t: t['text'].strip(), recent_tweets)) if best_tweet != None: twitter.post_tweet(best_tweet) encoded = unicode(best_tweet).encode('utf-8') print(encoded + '(' + str(len(encoded)) + ')') app_status['latest_tweet'] = encoded; else: print('Could not generate tweet') app_status['latest_tweet'] = 'Could not generate tweet' status.save(app_status)
def produce_next_tweet(app_status): app_status = status.load() # Just get the latest tweets tweets = twitter.get_timeline_tweets(800) tweets = filter_tweets(tweets) tweets = filter(lambda t:not t['user']['screen_name'] == twitter_settings.screen_name, tweets) if len(tweets) <= 1: print('Could not generate tweet (not enough eligible tweets)') app_status['latest_tweet'] = 'Could not generate tweet (not enough eligible tweets)' return recent_tweets = twitter.get_tweets(twitter_settings.screen_name, True) best_tweet = create_markovated_tweet(tweets, 140, map(lambda t: t['text'].strip(), recent_tweets)) if best_tweet != None: html_ent = re.findall(regexp, best_tweet) for e in html_ent: h = HTMLParser.HTMLParser() unescaped = h.unescape(e) #finds the unescaped value of the html entity best_tweet = best_tweet.replace(e, unescaped) #replaces html entity with unescaped value twitter.post_tweet(best_tweet, None) encoded = unicode(best_tweet).encode('utf-8') print(encoded + '(' + str(len(encoded)) + ')') app_status['latest_tweet'] = encoded; else: print('Could not generate tweet') app_status['latest_tweet'] = 'Could not generate tweet' status.save(app_status)
def reply_to_user(user, app_status): if user['protected']: print("@" + user['screen_name'] + " sorry, I can't process protected users :(") return screen_name = user['screen_name'] print(screen_name) tweets = filter_tweets(twitter.get_tweets(screen_name, True)) if len(tweets) <= 1: print("Not enough tweets") fail_reply = "@" + screen_name + " sorry, you need to tweet more (or tweet less @ mentions and links) :(" twitter.post_tweet(fail_reply) app_status['latest_reply'] = fail_reply return tweet_prefix = '@' + screen_name + ' markovated: ' ideal_tweet_length = 140 - len(tweet_prefix) best_tweet = create_markovated_tweet(tweets, ideal_tweet_length) if best_tweet != None: tweet = tweet_prefix + best_tweet twitter.post_tweet(tweet) encoded = unicode(tweet).encode('utf-8') print(encoded + '(' + str(len(encoded)) + ')') app_status['latest_reply'] = encoded else: print('<p>Could not generate reply</p>') app_status['latest_reply'] = 'Could not generate'
def reply_to_user(self, user, app_status): if user['protected']: self.response.out.write("@" + user['screen_name'] + " sorry, I can't process protected users :(") return screen_name = user['screen_name'] self.response.out.write("<h1>" + screen_name + "</h1>") tweets = filter_tweets(twitter.get_tweets(screen_name, True)) if len(tweets) <= 1: self.response.out.write("<p>Not enough tweets</p>") fail_reply = "@" + screen_name + " sorry, you need to tweet more (or tweet less @ mentions and links) :(" twitter.post_tweet(fail_reply) app_status['latest_reply'] = fail_reply return tweet_prefix = '@' + screen_name + ' markovated: ' ideal_tweet_length = 140 - len(tweet_prefix) best_tweet = create_markovated_tweet(tweets, ideal_tweet_length) if best_tweet != None: tweet = tweet_prefix + best_tweet twitter.post_tweet(tweet) self.response.out.write('<p>' + tweet + '</p>' + '(' + str(len(tweet_prefix + best_tweet)) + ')') app_status['latest_reply'] = tweet else: self.response.out.write('<p>Could not generate reply</p>') app_status['latest_reply'] = 'Could not generate'
def get(self): app_status = status.load() # Just get the latest tweets tweets = twitter.get_timeline_tweets(800) tweets = filter_tweets(tweets) tweets = filter(lambda t:not t['user']['screen_name'] == twitter_settings.screen_name, tweets) if len(tweets) <= 1: self.response.out.write('<p>Could not generate tweet (not enough eligible tweets)</p>') app_status['latest_tweet'] = 'Could not generate tweet (not enough eligible tweets)' return recent_tweets = twitter.get_tweets(twitter_settings.screen_name, True) best_tweet = create_markovated_tweet(tweets, 140, map(lambda t: t['text'].strip(), recent_tweets)) if best_tweet != None: twitter.post_tweet(best_tweet) self.response.out.write('<p>' + best_tweet + '</p>' + '(' + str(len(best_tweet)) + ')') app_status['latest_tweet'] = best_tweet; else: self.response.out.write('<p>Could not generate tweet</p>') app_status['latest_tweet'] = 'Could not generate tweet' status.save(app_status)
def produce_next_tweet(app_status): app_status = status.load() # Just get the latest tweets tweets = twitter.get_timeline_tweets(800) tweets = filter_tweets(tweets) tweets = filter( lambda t: not t['user']['screen_name'] == twitter_settings.screen_name, tweets) if len(tweets) <= 1: print('Could not generate tweet (not enough eligible tweets)') app_status[ 'latest_tweet'] = 'Could not generate tweet (not enough eligible tweets)' return recent_tweets = twitter.get_tweets(twitter_settings.screen_name, True) best_tweet = create_markovated_tweet( tweets, 140, map(lambda t: t['text'].strip(), recent_tweets)) if best_tweet != None: twitter.post_tweet(best_tweet) encoded = unicode(best_tweet).encode('utf-8') print(encoded + '(' + str(len(encoded)) + ')') app_status['latest_tweet'] = encoded else: print('Could not generate tweet') app_status['latest_tweet'] = 'Could not generate tweet' status.save(app_status)
def parle_avec_dessert(tweet): file = open(get_chemin('fonds'), 'rb') liste = map(tuple, csv.reader(file)) file.close() nombreFondsDessert = len(liste) # Ici, le tuple sélectionné sera sous la forme : # (X début, Y début, X fin, Y fin, taille, caractères max par ligne, nom du fond, R, G, B, nom de la police utilisée) fond = liste[random.randint(0, nombreFondsDessert-1)] phrase = ' '.join([x for x in tweet['text'].split() if not "#pd" in x.lower() and not "@_LEDESSERT_" in x and not "#dessertsays" in x.lower()]) image = gen_image(fond, phrase) buf = cStringIO.StringIO() image.save(buf, format='JPEG') texteTweet = "@{} Je suis LE DESSERT, et j'approuve ce tweet.".format(tweet['user']['screen_name']) media_id = twitter.upload_buffer_photo(buf.getvalue()) try : twitter.post_tweet(texteTweet, tweet['id'], media_id) except TwitterError as te: print("Erreur lors de l'envoi du statut\n" + te.content)
def dessert_waifu(tweet): file = open(get_chemin('waifus'), 'rb') liste = map(tuple, csv.reader(file)) file.close() nombreWaifus = len(liste) print("Nombre de waifus : {}".format(nombreWaifus)) # On sélectionne l'indice de la ligne selon l'alias Twitter de l'utilisateur idSel = id_from_string(tweet['user']['screen_name']) % nombreWaifus print("Id sélectionné : {}".format(idSel)) # Ici, le tuple waifu est sous la forme (Nom Dessert, Adresse dessert[, Media_id]) waifuSelected = liste[idSel] print(len(waifuSelected)) media_id = twitter.upload_photo("{}/images/{}.jpg".format(get_chemin("path"), idSel)) texteTweet = "@{} Votre waifu-dessert est : {} !".format(tweet['user']['screen_name'], waifuSelected[0]) try : twitter.post_tweet(texteTweet, tweet['id'], media_id) except TwitterError as te: print("Erreur lors de l'envoi du statut\n" + te.content)
def process_status(): try: twitter.post_tweet(pick_random_tweet()) except IOError as e: print("Erreur de lecture du fichier csv." + str(e)) except TwitterError as te: print("Erreur lors de l'envoi du statut\n" + te.content)
def main(): all_accounts = twitter.get_all_accounts() if len(all_accounts) >= 1: account = all_accounts[0] twitter.post_tweet(account, textview.text) console.hud_alert('ツイートしました。') else: console.hud_alert('Twitterアカウントが登録されていません。','error')
def process_status(): try: #print(pick_random_tweet()) twitter.post_tweet(pick_random_tweet(), None) except IOError as e: print("Erreur de lecture du fichier csv.") except TwitterError as te: print("Erreur de post du statut.\n" + te.content)
def tweet(text): all_accounts = twitter.get_all_accounts() if len(all_accounts) >= 1: account = all_accounts[0] # get main account text = dialogs.text_dialog( text=text, autocapitalization=ui.AUTOCAPITALIZE_SENTENCES) if text: twitter.post_tweet(account, text, parameters=None) console.hud_alert('Tweet Posted!', 'success', 1.5) else: console.hud_alert('Canceled', 'error', 1.5)
def post_twitter(desc, url): # Post description + url all_accounts = twitter.get_all_accounts() if len(all_accounts) >= 1: account = all_accounts[0] parameters = {'screen_name': account['username']} status, data = twitter.request(account, 'https://api.twitter.com/1.1/users/show.json', 'GET', parameters) # Trim description to tweetable size # 140 Total - 22 bit.ly URL = 118 shortdesc = (desc[:116] + '..') if len(desc) > 118 else data twitter.post_tweet(account, shortdesc +" "+ url) print('\n(2) Twitter Post Successful \n')
def post_main_tweet(board): text = header_msgs[state] peek = board.peek() if len(board.move_stack) > 0 else None arrow = [] if state != "new_game": if lastmove_text: text = text + "\nLast move chosen: " + lastmove_text if len(board.move_stack) >= 2: m = board.move_stack[-2] if board.turn == chess.WHITE else peek arrow = [(m.from_square, m.to_square)] if m else arrow # generate board image img_path = "chess.png" with open("chess.svg", "w") as f: f.write(chess.svg.board(board=board, lastmove=peek, arrows=arrow, size=400)) renderPM.drawToFile(svg2rlg("chess.svg"), img_path, fmt="PNG") media_id = upload_image(img_path) if not media_id: panic_clean_tweets() tweet_id = post_tweet(text, media_id=media_id) if not tweet_id: panic_clean_tweets() return tweet_id
def post_status(request): # Get the text for the tweet status text = request.POST.get('text') #request.POST.get('text') # Whoops, we didn't provide it! Let's tell the user. if not text: return JsonResponse({'errors': 'no text provided'}, status=400) # Do the posting thing :-) tweet = post_tweet(text) # Did it work? =(>.<)= if tweet.get('errors'): return JsonResponse( { 'errors': 'Couldn\'t post to Twitter: {0}'.format( tweet.get('errors')[0].get('message')) }, status=400) else: return JsonResponse( { 'url': 'https://twitter.com/{0}/status/{1}'.format( tweet.get('user').get('id'), tweet.get('id')), 'created_at': tweet.get('created_at'), 'screen_name': tweet.get('user').get('screen_name') }, status=200)
def post_twitter(desc, url): # Post description + url all_accounts = twitter.get_all_accounts() if len(all_accounts) >= 1: account = all_accounts[0] parameters = {'screen_name': account['username']} status, data = twitter.request( account, 'https://api.twitter.com/1.1/users/show.json', 'GET', parameters) # Trim description to tweetable size # 140 Total - 22 bit.ly URL = 118 shortdesc = (desc[:116] + '..') if len(desc) > 118 else data twitter.post_tweet(account, shortdesc + " " + url) print('\n(2) Twitter Post Successful \n')
def post_options(board, tweet_id): order = [chess.QUEEN, chess.KING, chess.ROOK, chess.BISHOP, chess.KNIGHT, chess.PAWN] moves = {chess.piece_name(p).title(): [] for p in order} piece_map = board.piece_map() for m in list(board.legal_moves): piece = chess.piece_name(piece_map[m.from_square].piece_type).title() moves[piece].append(m) poll_ids = [] for p in moves: if len(moves[p]) <= 0: continue op = [] for m in moves[p]: f = chess.square_name(m.from_square).upper() t = chess.square_name(m.to_square).upper() if m.promotion: prom = chess.piece_name(m.promotion).title() op.append(move_msg_prom.format(p, f, t, prom)) continue op.append(move_msg.format(p, f, t)) # Make sure we don't leave a poll with only 1 options (tweeter doesn't accept this) if len(op) % 4 == 1: op.append(filler_text) op = [op[i:i + 4] for i in range(0, len(op), 4)] head_tweet_id = post_tweet(p + " Moves:", reply_id=tweet_id, entries=op.pop(0)) if not head_tweet_id: poll_ids.append(tweet_id) panic_clean_tweets(poll_ids) poll_ids.append(head_tweet_id) for poll_ops in op: head_tweet_id = post_tweet(p + " cont...", reply_id=head_tweet_id, entries=poll_ops) if not head_tweet_id: poll_ids.append(tweet_id) panic_clean_tweets(poll_ids) poll_ids.append(head_tweet_id) return poll_ids
def twitter_to_action(text): try: if get_match(text, 'twitter')[0]: index = get_match(text, 'twitter')[1] if index == 0: twitter.post_tweet( ['@rokiier'], 'bots are awesome!' ) #aca usar expresiones regulares para personalizar to_user if index == 1: txt = twitter.read_tweet(True) arduino_to_action(txt) if index == 2: txt = twitter.get_tweet('starwars') arduino_to_action(txt) if index == 3: twitter.get_trends('local') except: pass
def reply_to_user(user, app_status, replyID): if user['protected']: print("@" + user['screen_name'] + " sorry, I can't process protected users :(") return screen_name = user['screen_name'] print(screen_name) tweets = filter_tweets(twitter.get_tweets(screen_name, True)) if len(tweets) <= 1: print("Not enough tweets") fail_reply = "@" + screen_name + " Pas assez de tweets. " twitter.post_tweet(fail_reply, None) app_status['latest_reply'] = fail_reply return tweet_prefix = '@' + screen_name + ' ' ideal_tweet_length = 140 - len(tweet_prefix) best_tweet = create_markovated_tweet(tweets, ideal_tweet_length) if best_tweet != None: html_ent = re.findall(regexp, best_tweet) for e in html_ent: h = HTMLParser.HTMLParser() unescaped = h.unescape(e) #finds the unescaped value of the html entity best_tweet = best_tweet.replace(e, unescaped) #replaces html entity with unescaped value tweet = tweet_prefix + best_tweet twitter.post_tweet(tweet, replyID) encoded = unicode(tweet).encode('utf-8') print(encoded + '(' + str(len(encoded)) + ')') app_status['latest_reply'] = encoded else: print('<p>Could not generate reply</p>') app_status['latest_reply'] = 'Could not generate'
def post_status(request): # Get the text for the tweet status text = request.POST.get('text') #request.POST.get('text') # Whoops, we didn't provide it! Let's tell the user. if not text: return JsonResponse({'errors': 'no text provided'}, status=400) # Do the posting thing :-) tweet = post_tweet(text) # Did it work? =(>.<)= if tweet.get('errors'): return JsonResponse({'errors': 'Couldn\'t post to Twitter: {0}'.format(tweet.get('errors')[0].get('message'))}, status=400) else: return JsonResponse({'url': 'https://twitter.com/{0}/status/{1}'.format(tweet.get('user').get('id'), tweet.get('id')), 'created_at': tweet.get('created_at'), 'screen_name': tweet.get('user').get('screen_name')}, status=200)
def action(): print("Performing action! lambda functions are awesome!") message = post_tweet(request.access_token(), tweet_message, params) del user_state['focus_tweet'] return message
def action(): return post_tweet(request.access_token(), tweet)
try: config.parse(options.config_file) if 'Python' in config.config: sys.path.append(config.config['Python']['local_lib_path']) if options.stats_date: target_datetime = datetime.datetime.strptime( options.stats_date, "%Y-%m-%d") tweet_contents = create_daily_stats_tweet(target_datetime.year, target_datetime.month, target_datetime.day) else: tweet_contents = create_score_tweet(options.score_id) if tweet_contents is None: logger.warning('No score data found.') sys.exit(1) if (options.dry_run): if isinstance(tweet_contents, basestring): tweet_contents = [tweet_contents] for tw in tweet_contents: print(tw.encode("UTF-8")) else: twitter = twitter.Twitter(logger=logger, **config.config['TwitterOAuth']) twitter.post_tweet(tweet_contents) except Exception: from traceback import format_exc logger.critical(format_exc())
import twitter, ui, dialogs, console all_accounts = twitter.get_all_accounts() if len(all_accounts) >= 1: account = all_accounts[0] # get main account text = dialogs.text_dialog(title='Tweet a Tweet', autocapitalization=ui.AUTOCAPITALIZE_SENTENCES) if len(text) < 140: twitter.post_tweet(account, text, parameters=None) console.hud_alert('Tweet Posted!', 'success', 1.5) else: console.hud_alert('Exceeded Character Limit', 'error', 1.5)
def post(): for tweet in get_newest(): post_tweet(tweet)
def tweet(account, text, param=None): if len(text) < 140: twitter.post_tweet(account, text, parameters=param) console.hud_alert('Tweet Posted', 'success', 1.5) else: console.hud_alert('Exceeded Character Limit', 'error', 1.5)
def process_message(data): if data['username'] == 'wdw': twitter.post_tweet(username, password, data['message'])
def action(): print ("Performing action! lambda functions are awesome!") message = post_tweet(request.access_token(), tweet_message, params) del user_state['focus_tweet'] return message
tAccts = twitter.get_all_accounts() if len(tAccts) >= 1: acct = tAccts[0] else: None # Return artist/song, post if nowPlaying: artist = nowPlaying.valueForProperty_('artist') title = nowPlaying.valueForProperty_('title') NP = '#NowPlaying: %s - "%s"' % (artist, title) checkPost = dialogs.alert('#NowPlaying', 'Currently playing: %s - "%s"' % (artist, title) + '. Tweet it?', 'Nope', 'Tweet', hide_cancel_button=True) if checkPost == 2: twitter.post_tweet(acct, NP) dialogs.alert('#NowPlaying', 'Posted', 'Okay', hide_cancel_button=True) elif checkPost == 1: dialogs.alert('#NowPlaying', 'Canceled', 'Okay', hide_cancel_button=True)
def tweet_closed_project(project): tweet = "Finalizei o projeto no TaskManager: " + project post_tweet(tweet)
def tweet_closed_task(task): tweet = "Finalizei a tarefa no TaskManager: " + task post_tweet(tweet)