def getListQuery(lis,dbase,coll): from pymongo import MongoClient as mc from collections import Counter check = 0 client = mc() if dbase == "testIndex": client = mc("192.168.103.25") if dbase=="wiki": return wiki.main(lis) db = client[dbase] results=db[coll].find({"keyword":{"$in":lis}},{"keyword":0,"_id":0}) listCounters = list(results) if dbase == "news" or dbase == "youtube": if len(lis) == len(listCounters): return list(getNewContent(listCounters)) else: check =1 result=SumDict({}) if check ==1: for listCounter in listCounters: result.merge(listCounter) sor=sorted(result, key=result.get, reverse=True) return sor else: return []
def main(): sid = SentimentIntensityAnalyzer() dic = {"freq": 0, "neg": 0, "neu": 0, "pos": 0, "comp": 0} tw_handle = input("Enter twitter handle : ") name = input("Enter name : ") wiki_search = name name = re.sub(" ", "", name) news_search_keys = [wiki_search] for i in range(len(news_search_keys)): news_search_keys[i] = news_search_keys[i].strip() f_name, ft = fetch(name, tw_handle) x2.main(news_search_keys, f_name, ft) try: summary = wiki.main(wiki_search) except: summary = None f = open(f_name, "r", encoding="utf-8") for line in f.readlines(): if "\t\t" in line: continue line = line.strip() sent_scores = sid.polarity_scores(line.split("\t")[4].strip()) dic["freq"] = dic["freq"] + 1 dic["neg"] = dic["neg"] + sent_scores['neg'] dic["pos"] = dic["pos"] + sent_scores['pos'] dic["neu"] = dic["neu"] + sent_scores['neu'] dic["comp"] = dic["comp"] + sent_scores['compound'] for elem in dic: if elem != "freq": dic[elem] = round(dic[elem] / dic["freq"], 2) overall_sent_sum = { "name": wiki_search, "compound": dic['comp'], "neg": dic['neg'], "neu": dic['neu'], "pos": dic['pos'], "summary": summary } print(json.dumps(overall_sent_sum))
#! /usr/bin/python2.6 """CGI test 3 (persistent data).""" import cgitb cgitb.enable() from wiki import main if __name__ == "__main__": main()
#!/usr/bin/env python """CGI test 3 (persistent data).""" import cgitb; cgitb.enable() from wiki import main if __name__ == "__main__": main()
def test_main(): main(PROJECT)
def test_main(cloud_config): main(cloud_config.project)
def test_main(cloud_config): main(cloud_config.GCLOUD_PROJECT)