def index(): if (request.method == 'POST'): query1 = request.form.get('query') api = TwitterClient() tweets = api.get_tweets(query=query1, count=200) # picking positive tweets from tweets ptweets = [tweet for tweet in tweets if tweet['sentiment'] == 'positive'] # percentage of positive tweets posper = 100 * len(ptweets) / len(tweets) # picking negative tweets from tweets ntweets = [tweet for tweet in tweets if tweet['sentiment'] == 'negative'] negper = 100 * len(ntweets) / len(tweets) # percentage of neutral tweets neuper = 100 * (len(tweets) - len(ntweets) - len(ptweets)) / len(tweets) resultdict = { "Positive tweets percentage": int(posper), "negative tweets percentage ": int(negper), "neutral tweets percentage": int(neuper) } return render_template('index.html', result=resultdict, ip=query1, pt=ptweets, nt=ntweets)
def submit(): keyword = request.form['keyword'] count = request.form['count'] # Get the tweets try: api = TwitterClient() tweets = api.get_tweets(query = keyword, count = count) positive_tweets = [tweet for tweet in tweets if tweet['sentiment'] == 'positive'] positive_tweets_percentage = round(len(positive_tweets)/len(tweets)*100, 2) negative_tweets = [tweet for tweet in tweets if tweet['sentiment'] == 'negative'] negative_tweets_percentage = round(len(negative_tweets)/len(tweets)*100, 2) neutral_percentage = round((len(tweets) - len(positive_tweets) - len(negative_tweets))/len(tweets)*100, 2) context = { 'ptweets': positive_tweets[:5], 'ntweets': negative_tweets[:5], 'ppercent': positive_tweets_percentage, 'npercent': negative_tweets_percentage, 'neutral': neutral_percentage } return render_template("results.html", context = context) except Exception as e: return str(e)
def get(self): twitter = TwitterClient() statuses = Status.getStatuses(20) user = twitter.getUser( self.username ) def urlify(txt): if txt: txt = re.sub('(https?:\/\/[-_.!~*\'()a-zA-Z0-9;/?:@&=+$,%#]+)', '<a href="\\1">Link</a>', txt) return txt def getMapUrl(loc,type): if not loc: return None; if type == "google" : url = u'http://maps.google.com/staticmap?' url += urllib.urlencode( { 'center' : str(loc.lat) + ',' + str(loc.lon), 'markers' : str(loc.lat) + ',' + str(loc.lon), 'size' : '460x320', 'zoom' : '15', 'key' : self.google_key, } ) else : url = u'http://tp.map.yahoo.co.jp/mk_map?' url += urllib.urlencode( { 'prop' : 'clip_map', 'scalebar' : 'off', 'pointer' : 'off', 'width' : '460', 'height' : '320', 'datum' : 'wgs84', 'lat' : loc.lat, 'lon' : loc.lon, 'pin' : str(loc.lat) + "," + str(loc.lon), 'sc' : 4, }) return url list = [] for status in statuses: list.append( { 'text' : status.text, 'reply' : urlify(status.reply), 'user_screen_name' : status.user_screen_name, 'user_profile_image_url' : status.user_profile_image_url, 'loc_url' : status.loc_url, 'map' : getMapUrl( status.loc_point , status.loc_type ), }) values = { 'list' : list, 'user' : user, } path = os.path.join(os.path.dirname(__file__), 'main.html') self.response.out.write( template.render(path,values))
def count_quotes(self): twc = TwitterClient() n_citacoes = [] for _, row in self.df.iterrows(): log.info("Fetching quotes for: {}".format(row['track_name'])) n_citacoes.append(twc.count(row['track_name'])) self.df['n_citacoes'] = n_citacoes columns = [ 'id', 'track_name', 'n_citacoes', 'size_bytes', 'price', 'prime_genre' ] self.df = self.df[columns]
def twitter(): firebase = Firebase("Twitter") docs = firebase.get_stream() for doc in docs: doc_id = doc.id doc = doc.to_dict() twitter_client = TwitterClient(doc["screen_name"]) unseen_tweets = twitter_client.get_user_timeline_unseen_tweets(doc["last_seen_id"]) if unseen_tweets: twitter_client.favorite_and_retweet(unseen_tweets, filter_word=doc.get("filter_word", "")) doc["last_seen_id"] = str(unseen_tweets[0].id) firebase.update(doc_id, doc)
def get(self): debug = self.request.get('debug',False) self.response.out.write('<ul>') #自分宛のreplyを取得 twitter = TwitterClient() replies = twitter.getReplies() replies.reverse() for reply in replies: text = reply['text'] texts = reply['text'].split() #全角スペースに対応 if len(texts) < 2: texts = reply['text'].split(u' ') if len(texts) < 2: self.response.out.write('<li>[%s] is irregure</li>'%(text)) continue keyword = texts[1] user = reply['user'] #自分のreplyは無視 if user['screen_name'] == self.username : self.response.out.write('<li>[%s] is my status</li>'%(text)) continue #既に処理済みのreplyも無視 if not Status.isNewStatus( reply['id'] ) : self.response.out.write('<li>[%s] is old status</li>'%(text)) continue #位置を取得 finder = LocationFinder() loc = finder.find( keyword ) if not loc: #見つからなかった mes = self.fail_message%( reply['user']['screen_name'] ,keyword) else: #見つかった mes = self.success_message[loc['type']]%( reply['user']['screen_name'] , loc['title'] , 'L:' + str(loc['lat']) + "," + str(loc['lon']) + ' ' + loc['url'] ) #返信した内容を保存 Status.saveStatus( reply,loc,mes ) #twitterのstatusを更新 if not debug: twitter.sendReply( mes , reply['id']) self.response.out.write('<li>[%s]:[%s]</li>'%(keyword,mes) ) self.response.out.write('</ul>')
from flask import Flask, request, render_template, jsonify from twitter import TwitterClient import json app = Flask(__name__) api = TwitterClient('') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() dados = jsonify({'data': tweets, 'count': len(tweets)}) return dados
# author = rhnvrm <*****@*****.**> import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@Kikokiki19') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@abdullahfachmi') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
from twitter import TwitterClient import json def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] def parse_env_json(): with open(".env.json") as f: return json.load(f) app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('Donald Trump', **parse_env_json()) @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query)
import os from flask import Flask, jsonify, redirect, render_template, url_for, request from twitter import TwitterClient import praw import tweepy from analysis import subredditAnalysis, userTweetAnalysis, searchTweetAnalysis, customTextAnalysis # Configure application app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@codedatt') # Ensure templates are auto-reloaded app.config["TEMPLATES_AUTO_RELOAD"] = True # To avoid caching of static files app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0 # Render routes @app.route('/') def index(): return (render_template("index.html")) @app.route('/reddit') def reddit(): return render_template("reddit-main.html")
import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) api = TwitterClient('@Djokarara') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
# author = rhnvrm <*****@*****.**> import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@GGodage') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
# Server import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client api = TwitterClient('@NagarajmvRahul') def str_to_bool(s): return s.lower() in ['yes', 'true', 1, 't'] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(str_to_bool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(str_to_bool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
# author = rhnvrm <*****@*****.**> import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@crs_macedo') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
# -*- coding: utf-8 -*- import requests import json from requests_oauthlib import OAuth1Session from twitter import TwitterClient consumer_key = '' consumer_secret = '' access_token = '' access_secret_token = '' twitter_client = TwitterClient(consumer_key, consumer_secret, access_token, access_secret_token) for tweet in twitter_client.get_tweets('naruto', n=100, lang='pt-br'): print(tweet['text'])
# author = rhnvrm <*****@*****.**> import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@SuvarnaVaidya3') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
# author = rhnvrm <*****@*****.**> import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@suwungtandon') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
# author = rhnvrm <*****@*****.**> import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@LynusMascot') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
# author = piyushvarshney <*****@*****.**> import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@PrivateCode3') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@Gauravkanwar07') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
# -*- coding: utf-8 -*- """ Created on Sat Jan 18 20:28:50 2020 @author: Shiv kumar """ import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@yum_dude') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment')
import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@gofornaman') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
# author = rhnvrm <*****@*****.**> import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@kurkute') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
import requests, time, os, math, threading from datetime import datetime, timedelta, timezone, time as dt_time from dateutil import parser from dotenv import load_dotenv from team import Team from image import build_image from twitter import TwitterClient from sms import SMSClient from db import DatabaseConnector from prediction import Prediction from utils import headers twitter_client = TwitterClient() sms_client = SMSClient() db_connector = DatabaseConnector() load_dotenv() dirname = os.path.dirname(__file__) LEAGUE_ID = os.getenv("LEAGUE_ID") LEAGUE_ID_PREV = os.getenv("LEAGUE_ID_PREV") def get_utc_timestamp(): return int(datetime.utcnow().timestamp()) def current_utc_day(): return datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0) def seconds_to(time):
# -*- coding: utf-8 -*- """ Created on Mon Jun 17 14:31:38 2019 @author: Verma """ import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient(query='data science') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower()))
import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) api = TwitterClient('@adambfad') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) resultSets = api.get_tweets() return jsonify({'resultSet': resultSets, 'count': len(resultSets)})
import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@anishsg3') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@Sirajology') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
# author = piyushvarshney <*****@*****.**> import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@yenhsravhsuyip') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('index.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) tweets = api.get_tweets() return jsonify({'data': tweets, 'count': len(tweets)})
import os from flask import Flask, request, render_template, jsonify from twitter import TwitterClient app = Flask(__name__) # Setup the client <query string, retweets_only bool, with_sentiment bool> api = TwitterClient('@AnoopBenny5') def strtobool(v): return v.lower() in ["yes", "true", "t", "1"] @app.route('/') def index(): return render_template('indexa.html') @app.route('/tweets') def tweets(): retweets_only = request.args.get('retweets_only') api.set_retweet_checking(strtobool(retweets_only.lower())) with_sentiment = request.args.get('with_sentiment') api.set_with_sentiment(strtobool(with_sentiment.lower())) query = request.args.get('query') api.set_query(query) st = request.args.get('st') api.set_styr(st) en = request.args.get('en')
import os, logging from flask import Flask, request, render_template, jsonify from twitter import TwitterClient logging.basicConfig( filename='logging.log', format='%(levelname)s - %(asctime)s - %(name)s - %(message)s', datefmt='%m/%d/%Y %H:%M:%S', level=logging.INFO) app = Flask(__name__) api = TwitterClient('Data') # abc xyz dgfcgfv jfhjhsdfjhdfnbgjk hjghhgbhgb logger = logging.getLogger(__name__) def strtobool(v): return v.lower() in ['yes', 'true', 't', 'l'] @app.route('/') def index(): logger.info('** Home page accessed **') logger.debug('** This is not debug **') return render_template('index.html') @app.route('/tweets')