def index(name=None): if request.method == 'POST': c = s.connect_db() res = s.filterLen(c, request.form['product'], request.form['category']) res2 = s.filter(c, request.form['product'], request.form['category']) tweets = [] #positive_text=[] #neutral_text=[] negative_text=[] print res #return render_template('index.html', tweets=res, negative_text=res2[2]) return render_template('index.html', tweets=res, negative_text=res2) else: return render_template('index.html', tweets=[], negative_text=[])
def map(name=None): if request.method == 'POST': c = s.connect_db() res = s.filter(c, text=request.form['form']) #res = format_js(res) tweets = [] for r in res: if(not str(r[2].encode("ascii", "ignore")) == "None"): st = "" st = "['" + r[0] + "','" + r[1] + "'," + r[2] + "]" tweets.append(st.encode("ascii","ignore")) #tweets.append(format_js(r)) #send = "[" + "], [".join(str(", ".join(str(y) for y in x)) for x in tweets) + "]" send = ", ".join(str(x) for x in tweets) send = "[" + send + "]" #js array [a,b,c] #populate google map return render_template('map.html', tweets=send) else: return render_template('map.html', tweets=[])
def __init__(self): self.test_url = db.test_url self.headers = db.headers self.db_obj = sql.connect_db()
# _*_ coding:utf-8_*_ import requests import asyncio import aiohttp from concurrent.futures import TimeoutError import logging from bs4 import BeautifulSoup from urllib import parse import sql import db from multiprocessing import Process db_obj = sql.connect_db() class get_cls(object): def __init__(self): self.test_url = db.test_url self.req_count = 0 self.headers = db.headers # headers = { # 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36' # } async def get_ip(self, url, proxy_url): # proxy_url = 'http://127.0.0.1:10800' try: async with aiohttp.ClientSession() as session: if proxy_url:
def before_request(): if "login" in session: sql.updateLastSeen(session["login"]) g.db = sql.connect_db()
def before_request(): g.db = sql.connect_db()
import tweepy consumer_key = "" consumer_secret = "" access_token = "" access_token_secret = "" auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token,access_token_secret) api = tweepy.API(auth) import sql as s c = s.connect_db() for tweet in tweepy.Cursor(api.search, q="ebola OR isis OR world series", count=100, result_type="recent", include_entities=True, lang="en").items(): if(tweet.geo): coords = tweet.geo['coordinates'] s.insert(c,tweet.created_at, tweet.text.strip().encode('ascii','ignore'), str(coords)) #print ("%s,%s,%s") % (tweet.created_at, tweet.text.encode('utf-8').strip(), coords) else: s.insert(c,tweet.created_at, tweet.text.strip().encode('ascii','ignore'), "None") #print ("%s,%s,%s") % (tweet.created_at, tweet.text.encode('utf-8').strip(), tweet.geo) #print tweet._json