from csv_operation import csv_reader from sentiment import anlaysis data2020 = csv_reader("2021-08southchinasea.csv", "data") print(data2020[0], "#" * 10, data2020[1], "#" * 10, " \n", data2020[2]) print("-*-" * 10) data2019 = csv_reader("2020-08southchinasea.csv", "data") print(data2019[0], "#" * 10, data2019[1], "#" * 10, " \n", data2019[2]) print("-" * 10, "tweets:") print(data2020[1][10], "\n", "#" * 10, "\n", data2019[1][10]) js_txt = ''' var DATA = { ''' print("\n1. Heat comparison") print(len(data2020), " VS ", len(data2019)) compare_txt = "'data2020':" + str(len(data2020)) + ", 'data2019':" + str( len(data2019)) js_txt += compare_txt # data2020full = csv_reader("2021_04_05southchinasea.csv", "data") data2020full = data2020 print("\n2. sentiment anlaysis") total_sentiment = 0
from csv_operation import csv_reader, csv_write from itertools import groupby import json movies = csv_reader("paulg.csv", "twitter_data") print('1sample', movies[0], "#" * 10, movies[1][12]) # i0_2 = 0 # i2_4 = 0 # i4_6 = 0 # i6_7 = 0 # i7_8 = 0 # year_revenue = [] for movie in movies: time = movie[2] i_str = movie[12] # print(i_str, type(i_str)) if i_str not in ('[]', 'mentions') : i_str = i_str.replace("\'", "\"") t = json.loads(i_str) print('name=paulg,name='+t[0]['screen_name']+",'"+time[:16]+"'") # name=elonmusk,name=@WholeMarsBlog,'2015-12-07 22:38' # for t in tlist: # name = t['name'] # if movie['vote_average'] is not None: # vote_count = float(movie['vote_average']) # if vote_count < 2:
time.sleep(2) try: places_result['next_page_token'] print('-' * 20, places_result['next_page_token']) except KeyError as e: print('Complete') else: printHotels(searchString, cityid, cityname, jobname, next=places_result['next_page_token']) if __name__ == "__main__": citylist = csv_reader('rank_cities.csv') print(citylist[0], citylist[0][0], citylist[0][1]) destination = citylist[0][1] places = [] # printHotels(mymakets_A[0] + ' near ' + citylist[0][1], citylist[0][0], citylist[0][1], mymakets_A[0]) # print(len(places), places[0], '#'*20) # print('\n') # printHotels(mymakets_A[0] + ' near ' + citylist[1][1], citylist[1][0],citylist[1][1], mymakets_A[0]) # print(len(places), places[0], '#'*20) for jobname in mymakets_A: for cityrow in citylist: cityid = cityrow[0] cityname = cityrow[1] if int(cityid) >= 100 and int(cityid) < 200: print( colored(jobname + cityid + cityname,
from csv_operation import csv_reader from sentiment import anlaysis data2020 = csv_reader("2021_q1_south_china_sea.csv", "data") print(data2020[0], "#" * 10, data2020[1], "#" * 10, " \n", data2020[2]) print("-*-" * 10) data2019 = csv_reader("2020_q1_south_china_sea.csv", "data") print(data2019[0], "#" * 10, data2019[1], "#" * 10, " \n", data2019[2]) print("-" * 10, "tweets:") print(data2020[1][10], "\n", "#" * 10, "\n", data2019[1][10]) js_txt = ''' var DATA = { ''' print("\n1. Heat comparison") print(len(data2020), " VS ", len(data2019)) compare_txt = "'data2020':" + str(len(data2020)) + ", 'data2019':" + str( len(data2019)) js_txt += compare_txt data2020full = csv_reader("2021_q1_south_china_sea.csv", "data") print("\n2. sentiment anlaysis") total_sentiment = 0 num_positive = 0
from csv_operation import csv_reader from sentiment import anlaysis data2020 = csv_reader("2021django.csv", "data") print(data2020[0], "#" * 10, data2020[1], "#" * 10, " \n", data2020[2]) print("-*-" * 10) data2019 = csv_reader("2021flask.csv", "data") print(data2019[0], "#" * 10, data2019[1], "#" * 10, " \n", data2019[2]) print("-" * 10, "tweets:") print(data2020[1][10], "\n", "#" * 10, "\n", data2019[1][10]) js_txt = ''' var DATA = { ''' print("\n1. Heat comparison") print(len(data2020), " VS ", len(data2019)) compare_txt = "'data2020':" + str(len(data2020)) + ", 'data2019':" + str( len(data2019)) js_txt += compare_txt data2020full = csv_reader("2021full.csv", "data") print("\n2. sentiment anlaysis") total_sentiment = 0 num_positive = 0
from csv_operation import csv_reader from sentiment import anlaysis data2020 = csv_reader("2020senkafu.csv", "data") print(data2020[0], "#" * 10, data2020[1], "#" * 10, " \n", data2020[2]) print("-*-" * 10) data2019 = csv_reader("2019senkafu.csv", "data") print(data2019[0], "#" * 10, data2019[1], "#" * 10, " \n", data2019[2]) print("-" * 10, "tweets:") print(data2020[1][10], "\n", "#" * 10, "\n", data2019[1][10]) js_txt = ''' var DATA = { ''' print("\n1. Heat comparison") print(len(data2020), " VS ", len(data2019)) compare_txt = "'data2020':" + str(len(data2020)) + ", 'data2019':" + str( len(data2019)) js_txt += compare_txt data2020full = csv_reader("2020senkafu_full.csv", "data") print("\n2. sentiment anlaysis") total_sentiment = 0 num_positive = 0
#找出电影演员和票房总收入的关联 from csv_operation import csv_reader, csv_write from itertools import groupby import json movies = csv_reader("tmdb_5000_movies.csv", "data") print('1sample', movies[0], "#" * 10) print('len=', len(movies)) t = json.loads(movies[0]['keywords']) print(len(t), t[0], t[1]) year_revenue = [] for movie in movies: revenue = int(movie['revenue']) tlist = json.loads(movie['keywords']) for t in tlist: name = t['name'] # print(year, revenue) item = [name, revenue] year_revenue.append(item) print(year_revenue) print('----#--------#--------#----') my_list2 = [] keyword_revenue = [] keyword_revenue.append(['keyword', 'revenue']) justwords = [] for i, g in groupby(sorted(year_revenue), key=lambda x: x[0]):
#找出电影演员和票房总收入的关联 from csv_operation import csv_reader, csv_write from itertools import groupby import json movies = csv_reader("tmdb_5000_credits.csv", "data") print('1sample', movies[0], "#" * 10) print('len=', len(movies)) t = json.loads(movies[0]['cast']) print(len(t), t[0], t[1]) year_revenue = [] for movie in movies: tlist = json.loads(movie['cast']) for t in tlist: name = t['name'] # print(year, revenue) item = [name, 1] year_revenue.append(item) print(year_revenue) print('----#--------#--------#----') my_list2 = [] for i, g in groupby(sorted(year_revenue), key=lambda x: x[0]): count_v = sum(v[1] for v in g) if count_v > 30: my_list2.append({'word': i, 'size': count_v})
from csv_operation import csv_reader from sentiment import anlaysis data2020 = csv_reader("2020file.csv", "data") print(data2020[0], "#" * 10, data2020[1], "#" * 10, " \n", data2020[2]) print("-*-" * 10) data2019 = csv_reader("2019file.csv", "data") print(data2019[0], "#" * 10, data2019[1], "#" * 10, " \n", data2019[2]) print("-" * 10, "tweets:") print(data2020[1][10], "\n", "#" * 10, "\n", data2019[1][10]) js_txt = ''' var DATA = { ''' print("\n1. Heat comparison") print(len(data2020), " VS ", len(data2019)) compare_txt = "'data2020':" + str(len(data2020)) + ", 'data2019':" + str(len(data2019)) js_txt += compare_txt data2020full = csv_reader("2020_total_file.csv", "data") print("\n2. sentiment anlaysis")
from csv_operation import csv_reader from sentiment import anlaysis data2020 = csv_reader("2020tw.csv", "data") print(data2020[0], "#" * 10, data2020[1], "#" * 10, " \n", data2020[2]) print("-*-" * 10) data2019 = csv_reader("2019tw.csv", "data") print(data2019[0], "#" * 10, data2019[1], "#" * 10, " \n", data2019[2]) print("-" * 10, "tweets:") print(data2020[1][10], "\n", "#" * 10, "\n", data2019[1][10]) js_txt = ''' var DATA = { ''' print("\n1. Heat comparison") print(len(data2020), " VS ", len(data2019)) compare_txt = "'data2020':" + str(len(data2020)) + ", 'data2019':" + str(len(data2019)) js_txt += compare_txt data2020full = csv_reader("2020tw_full.csv", "data") print("\n2. sentiment anlaysis")
from csv_operation import csv_reader from sentiment import anlaysis # twint -s "Nezha" --since 2021-01-01 -o Nezha.csv --csv # twint -s "senkaku islands" --since 2021-08-01 -o senkaku.csv --csv # twint -s "south China sea" --since 2021-08-01 -o southchinasea.csv --csv # proxychains4 twint -s "中国经济" --since 2021-11-10 -o china_economy.csv --csv data2020 = csv_reader("2021-08senkaku.csv", "data") print(data2020[0], "#" * 10, data2020[1], "#" * 10, " \n", data2020[2]) print("-*-" * 10) data2019 = csv_reader("2020-08senkaku.csv", "data") print(data2019[0], "#" * 10, data2019[1], "#" * 10, " \n", data2019[2]) print("-" * 10, "tweets:") print(data2020[1][10], "\n", "#" * 10, "\n", data2019[1][10]) js_txt = ''' var DATA = { ''' print("\n1. Heat comparison") print(len(data2020), " VS ", len(data2019)) compare_txt = "'data2021':" + str(len(data2020)) + ", 'data2020':" + str( len(data2019)) js_txt += compare_txt # data2020full = csv_reader("2021-06senkaku.csv", "data") data2020full = data2020
import pandas as pd from csv_operation import csv_reader from sentiment import anlaysis import time # 检查数据集是否正常 data2020 = csv_reader("sum.csv", "data") print(data2020[0], "#" * 10, data2020[1], "#" * 10, " \n", data2020[2]) print("-" * 10, "tweets:") # print(data2020[1][3]) # print("data2020[1][10]=", data2020[1][10], "\n", "@" * 10) print("start", "*-* *-* *-* *-* *-* " * 10) # 处理基于天的热度 from collections import defaultdict appearances = defaultdict(int) for curr in data2020: # curr = curr[0].split(',') print('curr=>' * 3, curr) if len(curr) >= 3 and "2020" in curr[3]: appearances[curr[3]] += 1 print('appearances=> ' * 10, appearances) # time.sleep(100) # 持久化为其他程序做处理 import pickle