def findRelavantArticles(): es = Elasticsearch() comparetweet = TwitterSearchV2.userSearchbyName("drubix_cube") comparetweet1 = comparetweet.split() ct1 = "" for wc in range(500): ct1 = ct1 + " " + comparetweet1[wc] q2= { "size": 8, "query": { "match": {"text": ct1} }} resA = es.search(index='twf-index',body = q2) urlList = [] for hit in resA['hits']['hits']: urlList.append("%(url)s" % hit["_source"]) return urlList
def personewspage(): if request.method == "POST": twitter_handle = request.form['text'] listOfTextFiles = ["BodyTexts.json"] es = Elasticsearch() es.indices.create(index='twf-index', ignore=400) i = 0 for fileName in listOfTextFiles: with open(fileName) as bodytx: tweets = {} tweets = json.load(bodytx) for key in tweets.keys(): doc = { 'url' : key, 'text' : tweets[key] } es.index(index = 'twf-index' , doc_type='tweet',id = i, body = doc) i = i+1 es.indices.refresh(index='twf-index') comparetweet = TwitterSearchV2.userSearchbyName(twitter_handle) comparetweet1 = comparetweet.split() ct1 = "" for wc in range(500): ct1 = ct1 + " " + comparetweet1[wc] q2= { "size": 8, "query": { "match": {"text": ct1} }} resA = es.search(index='twf-index',body = q2) urlList = [] for hit in resA['hits']['hits']: urlList.append("%(url)s" % hit["_source"]) return render_template('persoNews.html', urlList=urlList)