repo
stringlengths
2
99
file
stringlengths
13
225
code
stringlengths
0
18.3M
file_length
int64
0
18.3M
avg_line_length
float64
0
1.36M
max_line_length
int64
0
4.26M
extension_type
stringclasses
1 value
tweet-analysis-2020
tweet-analysis-2020-main/app/twitter_service.py
import os from pprint import pprint #from app.timelines.status_parser import parse_urls, parse_full_text, parse_timeline_status from dotenv import load_dotenv from tweepy import OAuthHandler, API, Cursor from tweepy.error import TweepError load_dotenv() CONSUMER_KEY = os.getenv("TWITTER_API_KEY", default="OO...
6,032
34.280702
169
py
tweet-analysis-2020
tweet-analysis-2020-main/app/file_storage.py
import os from pprint import pprint from dotenv import load_dotenv from app import DATA_DIR, seek_confirmation from app.decorators.datetime_decorators import logstamp from app.gcs_service import GoogleCloudStorageService load_dotenv() DIRPATH = os.getenv("DIRPATH", default="example/file_storage") WIFI = (os.getenv...
2,158
31.712121
130
py
tweet-analysis-2020
tweet-analysis-2020-main/app/__init__.py
import os import time from dotenv import load_dotenv load_dotenv() APP_ENV = os.getenv("APP_ENV", "development") SERVER_NAME = os.getenv("SERVER_NAME", "mjr-local") # the name of your Heroku app (e.g. "impeachment-tweet-analysis-9") SERVER_DASHBOARD_URL = f"https://dashboard.heroku.com/apps/{SERVER_NAME}" DATA_DI...
745
26.62963
119
py
tweet-analysis-2020
tweet-analysis-2020-main/app/job.py
import time from app.decorators.datetime_decorators import logstamp from app.decorators.number_decorators import fmt_n class Job(): def __init__(self): self.start_at = None self.end_at = None self.duration_seconds = None self.counter = None # represents the number of items process...
962
23.692308
97
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_follower_graphs/pg_grapher.py
#from memory_profiler import profile # #from networkx import DiGraph # #from app import seek_confirmation #from app.decorators.datetime_decorators import logstamp #from app.decorators.number_decorators import fmt_n #from app.pg_pipeline.pg_service import PgService #from app.retweet_graphs_v2.graph_storage import GraphS...
2,225
29.493151
106
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_follower_graphs/bq_grapher.py
from memory_profiler import profile from networkx import DiGraph from app import seek_confirmation from app.decorators.datetime_decorators import logstamp from app.decorators.number_decorators import fmt_n from app.bq_service import BigQueryService from app.retweet_graphs_v2.graph_storage import GraphStorage from app...
1,924
28.166667
102
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_follower_graphs/bq_prep.py
from app.bq_service import BigQueryService if __name__ == "__main__": bq_service = BigQueryService(verbose=True) print("FLATTENING USER FRIENDS TABLE...") bq_service.destructively_migrate_user_friends_flat() print("BOTS ABOVE 80...") bq_service.destructively_migrate_bots_table() print("BOT...
404
24.3125
58
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_analysis/top_status_tags.py
import os from collections import Counter from pandas import DataFrame, read_csv import re from app.bq_service import BigQueryService from app.file_storage import FileStorage from app.job import Job from app.decorators.number_decorators import fmt_n LIMIT = os.getenv("LIMIT") # 1000 # None # os.getenv("LIMIT") BAT...
4,422
34.384
114
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_analysis/download_tweet_details_v6.py
import os from pandas import read_csv, DataFrame from app.file_storage import FileStorage from app.bq_service import BigQueryService from app.job import Job from app.decorators.number_decorators import fmt_n LIMIT = os.getenv("LIMIT") # for development purposes BATCH_SIZE = int(os.getenv("BATCH_SIZE", default="10_0...
1,331
30.714286
130
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_analysis/user_details_vq.py
import os from pprint import pprint import json from pandas import DataFrame, read_csv from scipy.stats import ks_2samp #, ttest_ind from app.bq_service import BigQueryService from app.file_storage import FileStorage from app.job import Job from app.decorators.number_decorators import fmt_n from app.decorators.datet...
4,852
37.515873
137
py
tweet-analysis-2020
tweet-analysis-2020-main/app/pg_pipeline/tweets.py
import os from dotenv import load_dotenv load_dotenv() START_AT = os.getenv("START_AT", default="2019-12-10") END_AT = os.getenv("END_AT", default="2020-02-10") from app.pg_pipeline import Pipeline if __name__ == "__main__": pipeline = Pipeline() print("START_AT:", START_AT) print("END AT:", END_AT) ...
383
19.210526
62
py
tweet-analysis-2020
tweet-analysis-2020-main/app/pg_pipeline/bot_followers.py
import os from app.pg_pipeline import Pipeline BOT_MIN = float(os.getenv("BOT_MIN", default="0.8")) if __name__ == "__main__": pipeline = Pipeline() pipeline.download_bot_followers(bot_min=BOT_MIN)
212
15.384615
52
py
tweet-analysis-2020
tweet-analysis-2020-main/app/pg_pipeline/pg_service.py
from psycopg2 import connect from psycopg2.extras import DictCursor from app.decorators.number_decorators import fmt_n from app.decorators.datetime_decorators import logstamp from app.pg_pipeline.models import DATABASE_URL, USER_FRIENDS_TABLE_NAME class PgService: def __init__(self, database_url=DATABASE_URL): ...
3,349
34.638298
164
py
tweet-analysis-2020
tweet-analysis-2020-main/app/pg_pipeline/community_predictions.py
#import os #from dotenv import load_dotenv #load_dotenv() #START_AT = os.getenv("START_AT", default="2019-12-12") #END_AT = os.getenv("END_AT", default="2020-02-10") from app.pg_pipeline import Pipeline if __name__ == "__main__": pipeline = Pipeline() #print("START_AT:", START_AT) #print("END AT:", EN...
451
22.789474
78
py
tweet-analysis-2020
tweet-analysis-2020-main/app/pg_pipeline/user_friends.py
from app.pg_pipeline import Pipeline if __name__ == "__main__": pipeline = Pipeline() pipeline.download_user_friends()
132
12.3
36
py
tweet-analysis-2020
tweet-analysis-2020-main/app/pg_pipeline/models.py
import os from dotenv import load_dotenv from sqlalchemy import create_engine, Column, Integer, BigInteger, String, Boolean, DateTime, ARRAY, TIMESTAMP from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from sqlalchemy.orm.exc import NoResultFound load_dotenv() DATABASE_U...
6,147
37.425
197
py
tweet-analysis-2020
tweet-analysis-2020-main/app/pg_pipeline/__init__.py
import time import os from dotenv import load_dotenv from app import APP_ENV from app.decorators.datetime_decorators import logstamp from app.decorators.number_decorators import fmt_n from app.bq_service import BigQueryService from app.pg_pipeline.models import BoundSession, db, Tweet, UserFriend, UserDetail, Retweet...
10,402
38.555133
186
py
tweet-analysis-2020
tweet-analysis-2020-main/app/pg_pipeline/user_details.py
from app.pg_pipeline import Pipeline if __name__ == "__main__": pipeline = Pipeline() pipeline.download_user_details() # takes about 50 minutes for 3.6M users in batches of 2500
191
18.2
95
py
tweet-analysis-2020
tweet-analysis-2020-main/app/pg_pipeline/retweeter_details.py
from app.pg_pipeline import Pipeline if __name__ == "__main__": pipeline = Pipeline() pipeline.download_retweeter_details() # takes about 16 minutes for 2.7M users in batches of 2500
196
18.7
100
py
tweet-analysis-2020
tweet-analysis-2020-main/app/pg_pipeline/investigate.py
from app.decorators.datetime_decorators import logstamp from app.decorators.number_decorators import fmt_n from app.pg_pipeline.pg_service import PgService def fetch_in_batches(): pg_service = PgService() pg_service.cursor.execute("SELECT user_id, screen_name, friend_count FROM user_friends LIMIT 1000;") ...
1,658
26.65
165
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_impact_v4/daily_active_edge_downloader.py
import os from pandas import read_csv, DataFrame from app.retweet_graphs_v2.k_days.generator import DateRangeGenerator from app.file_storage import FileStorage from app.bq_service import BigQueryService from app.job import Job from app.decorators.number_decorators import fmt_n LIMIT = os.getenv("LIMIT") # for deve...
2,704
38.779412
142
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_impact_v4/daily_active_edge_friend_grapher_v2.py
import os from pandas import DataFrame, read_csv from networkx import DiGraph, write_gpickle, read_gpickle from memory_profiler import profile from app.decorators.number_decorators import fmt_n from app.job import Job from app.bq_service import BigQueryService from app.file_storage import FileStorage DATE = os.get...
3,954
32.803419
130
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_impact_v4/active_edge_v6_downloader.py
import os from pandas import read_csv, DataFrame from app.file_storage import FileStorage from app.bq_service import BigQueryService from app.job import Job from app.decorators.number_decorators import fmt_n LIMIT = os.getenv("LIMIT") # for development purposes BATCH_SIZE = int(os.getenv("BATCH_SIZE", default="10_0...
1,296
31.425
130
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_impact_v4/daily_active_edge_friend_grapher.py
import os from pandas import DataFrame, read_csv from networkx import DiGraph, write_gpickle, read_gpickle from memory_profiler import profile from app.decorators.number_decorators import fmt_n from app.job import Job from app.bq_service import BigQueryService from app.file_storage import FileStorage DATE = os.get...
6,941
29.716814
125
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_impact_v4/active_edge_v7_downloader.py
import os from pandas import read_csv, DataFrame from app.file_storage import FileStorage from app.bq_service import BigQueryService from app.job import Job from app.decorators.number_decorators import fmt_n LIMIT = os.getenv("LIMIT") # for development purposes BATCH_SIZE = int(os.getenv("BATCH_SIZE", default="10_0...
2,028
33.982759
130
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_impact_v4/daily_active_user_friend_grapher.py
import os from pandas import DataFrame, read_csv from networkx import DiGraph, write_gpickle, read_gpickle from app.decorators.number_decorators import fmt_n from app.job import Job from app.bq_service import BigQueryService from app.file_storage import FileStorage DATE = os.getenv("DATE", default="2020-01-23") TWE...
4,479
31.941176
111
py
tweet-analysis-2020
tweet-analysis-2020-main/app/nlp_v2/model_promotion.py
import os from app.nlp.model_storage import ModelStorage SOURCE = os.getenv("SOURCE", default="nlp_v2/models/dev/multinomial_nb") DESTINATION = os.getenv("DESTINATION", default="nlp_v2/models/best/multinomial_nb") if __name__ == "__main__": storage = ModelStorage(dirpath=SOURCE) storage.promote_model(desti...
340
25.230769
83
py
tweet-analysis-2020
tweet-analysis-2020-main/app/nlp_v2/bulk_predict.py
import os from pandas import DataFrame, read_csv from app import seek_confirmation, DATA_DIR from app.job import Job from app.bq_service import BigQueryService from app.nlp.model_storage import ModelStorage LIMIT = os.getenv("LIMIT") BATCH_SIZE = int(os.getenv("BATCH_SIZE", default="100000")) CSV_FILEPATH = os.path...
2,580
32.960526
140
py
tweet-analysis-2020
tweet-analysis-2020-main/app/nlp_v2/model_training.py
import os from datetime import datetime from pprint import pprint from pandas import DataFrame, read_csv from sklearn.model_selection import train_test_split from sklearn.metrics import classification_report # accuracy_score from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.linear_model import...
7,434
34.574163
236
py
tweet-analysis-2020
tweet-analysis-2020-main/app/nlp_v2/client.py
import os from app.nlp.model_storage import ModelStorage MODEL_DIRPATH = os.getenv("MODEL", default="nlp_v2/models/best/multinomial_nb") if __name__ == "__main__": storage = ModelStorage(dirpath=MODEL_DIRPATH) tv = storage.load_vectorizer() print(type(tv)) print("FEATURES / TOKENS:", len(tv.get_fea...
693
22.133333
79
py
tweet-analysis-2020
tweet-analysis-2020-main/app/nlp_v2/bulk_predict_old.py
# Don't use this method. Just fetch tweets once otherwise its very expensive #import os # #from app import seek_confirmation #from app.job import Job #from app.bq_service import BigQueryService #from app.nlp.model_storage import ModelStorage # #LIMIT = os.getenv("LIMIT") #BATCH_SIZE = int(os.getenv("BATCH_SIZE", defau...
2,078
33.65
112
py
tweet-analysis-2020
tweet-analysis-2020-main/app/nlp_v2/bert_score_uploader.py
import os from pandas import read_csv from app import DATA_DIR, seek_confirmation from app.job import Job from app.bq_service import BigQueryService from app.retweet_graphs_v2.k_days.generator import DateRangeGenerator BATCH_SIZE = int(os.getenv("BATCH_SIZE", default=25000)) # the max number of processed users to s...
1,628
37.785714
202
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_communities/retweet_analyzer.py
import os from functools import lru_cache from pandas import DataFrame import matplotlib.pyplot as plt import plotly.express as px import squarify from app import APP_ENV, seek_confirmation from app.decorators.datetime_decorators import logstamp from app.decorators.number_decorators import fmt_n from app.bot_communi...
7,116
41.873494
174
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_communities/bot_similarity_grapher.py
import os from networkx import write_gpickle, read_gpickle, jaccard_coefficient, Graph from app import seek_confirmation from app.bot_communities.bot_retweet_grapher import BotRetweetGrapher from app.decorators.datetime_decorators import logstamp from app.decorators.number_decorators import fmt_n class BotSimilarit...
5,089
40.382114
141
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_communities/token_analyzer.py
from collections import Counter from pandas import DataFrame from gensim.corpora import Dictionary from gensim.models.ldamulticore import LdaMulticore #from gensim.models import TfidfModel def summarize_token_frequencies(token_sets): """ Param token_sets : a list of tokens for each document in a collection ...
2,787
40
210
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_communities/bot_profile_analyzer_v2.py
import os from app import DATA_DIR from app.bq_service import BigQueryService from app.file_storage import FileStorage from app.bot_communities.tokenizers import Tokenizer #, SpacyTokenizer from app.bot_communities.token_analyzer import summarize_token_frequencies from pandas import DataFrame if __name__ == "__main...
3,836
48.192308
163
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_communities/bot_tweet_analyzer_v2.py
import os from app import DATA_DIR, seek_confirmation from app.decorators.datetime_decorators import logstamp from app.decorators.number_decorators import fmt_n from app.bq_service import BigQueryService from app.file_storage import FileStorage from app.bot_communities.tokenizers import Tokenizer from app.bot_communit...
4,750
45.126214
147
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_communities/bot_retweet_grapher.py
import os from networkx import DiGraph, read_gpickle from app.retweet_graphs_v2.retweet_grapher import RetweetGrapher BOT_MIN = float(os.getenv("BOT_MIN", default="0.8")) class BotRetweetGrapher(RetweetGrapher): def __init__(self, bot_min=BOT_MIN): self.bot_min = float(bot_min) super().__init__...
1,232
27.022727
102
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_communities/tokenizers.py
import os from collections import Counter from functools import lru_cache from pprint import pprint import re from dotenv import load_dotenv from pandas import DataFrame from nltk.corpus import stopwords as NLTK_STOPWORDS from gensim.parsing.preprocessing import STOPWORDS as GENSIM_STOPWORDS from spacy.lang.en.stop_wo...
5,396
38.108696
137
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_communities/tweet_analyzer.py
import os from pandas import DataFrame, read_csv from app.decorators.datetime_decorators import dt_to_s, logstamp from app.decorators.number_decorators import fmt_n from app.bot_communities.spectral_clustermaker import SpectralClustermaker BATCH_SIZE = 50_000 # we are talking about downloading 1-2M tweets class Co...
2,690
36.901408
159
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_communities/daily_retweet_analyzer.py
import os from functools import lru_cache import time from concurrent.futures import as_completed, ProcessPoolExecutor, ThreadPoolExecutor from threading import current_thread #, #Thread, Lock, BoundedSemaphore from dotenv import load_dotenv from pandas import to_datetime from app import APP_ENV, seek_confirmation f...
4,807
41.175439
157
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_communities/spectral_clustermaker.py
import os from functools import lru_cache from dotenv import load_dotenv from pandas import DataFrame from networkx import adjacency_matrix, Graph from sklearn.cluster import SpectralClustering import matplotlib.pyplot as plt from app import seek_confirmation, APP_ENV from app.bot_communities.bot_similarity_grapher i...
4,582
38.852174
181
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_communities/csv_storage.py
import os from pandas import DataFrame, read_csv from app.decorators.datetime_decorators import dt_to_s, logstamp from app.decorators.number_decorators import fmt_n from app.bot_communities.spectral_clustermaker import SpectralClustermaker BATCH_SIZE = 50_000 # we are talking about downloading millions of records ...
3,037
39.506667
163
py
tweet-analysis-2020
tweet-analysis-2020-main/app/bot_communities/bot_profile_analyzer_v1.py
import os from app import DATA_DIR from app.bq_service import BigQueryService from app.bot_communities.tokenizers import Tokenizer, SpacyTokenizer from app.bot_communities.token_analyzer import summarize_token_frequencies from pandas import DataFrame if __name__ == "__main__": local_dirpath = os.path.join(DATA_...
4,124
40.25
130
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_graphs/bq_topic_grapher.py
import os from networkx import DiGraph from memory_profiler import profile from dotenv import load_dotenv from app.decorators.datetime_decorators import logstamp from app.decorators.number_decorators import fmt_n from app.friend_graphs.bq_grapher import BigQueryGrapher load_dotenv() USERS_LIMIT = int(os.getenv("US...
3,146
36.464286
196
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_graphs/base_grapher.py
import time import os from datetime import datetime as dt import pickle import json from dotenv import load_dotenv from networkx import DiGraph, write_gpickle from pandas import DataFrame from app import APP_ENV, DATA_DIR from app.decorators.datetime_decorators import logstamp from app.decorators.number_decorators i...
7,716
40.047872
162
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_graphs/psycopg_batch_grapher.py
from networkx import DiGraph from memory_profiler import profile from app.friend_graphs.psycopg_grapher import PsycopgGrapher class Grapher(PsycopgGrapher): @profile def perform(self): self.start() self.graph = DiGraph() self.cursor.execute(self.sql) while True: r...
1,011
28.764706
85
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_graphs/psycopg_grapher.py
import psycopg2 from networkx import DiGraph from memory_profiler import profile from app import APP_ENV from app.pg_pipeline.models import DATABASE_URL, USER_FRIENDS_TABLE_NAME from app.decorators.datetime_decorators import logstamp from app.decorators.number_decorators import fmt_n from app.friend_graphs.base_graph...
2,660
34.959459
155
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_graphs/bq_list_grapher.py
import pickle from networkx import DiGraph from memory_profiler import profile from app.decorators.datetime_decorators import logstamp from app.decorators.number_decorators import fmt_n from app.friend_graphs.bq_grapher import BigQueryGrapher class BigQueryListGrapher(BigQueryGrapher): @profile def perform...
2,112
30.073529
94
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_graphs/psycopg_list_grapher.py
from networkx import DiGraph from memory_profiler import profile from app.decorators.datetime_decorators import logstamp from app.decorators.number_decorators import fmt_n from app.friend_graphs.psycopg_grapher import PsycopgGrapher class Grapher(PsycopgGrapher): @profile def perform(self): self.ed...
1,545
26.607143
98
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_graphs/bq_grapher.py
from networkx import DiGraph from memory_profiler import profile from app.bq_service import BigQueryService from app.decorators.datetime_decorators import logstamp from app.decorators.number_decorators import fmt_n from app.friend_graphs.base_grapher import BaseGrapher class BigQueryGrapher(BaseGrapher): def __...
1,768
30.035088
128
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_graphs/psycopg_set_grapher.py
from networkx import DiGraph from memory_profiler import profile from app.friend_graphs.psycopg_grapher import PsycopgGrapher class Grapher(PsycopgGrapher): @profile def perform(self): self.edges = set() # set prevents duplicates self.running_results = [] self.cursor.execute(self.sq...
1,400
29.456522
101
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_graphs/graph_analyzer.py
import os import time from functools import lru_cache from networkx import read_gpickle, DiGraph from dotenv import load_dotenv from memory_profiler import profile from app import DATA_DIR from app.decorators.number_decorators import fmt_n from app.friend_graphs.base_grapher import BaseGrapher load_dotenv() JOB_ID...
2,266
30.486111
106
py
tweet-analysis-2020
tweet-analysis-2020-main/app/nlp/model_promotion.py
import os from app.nlp.model_storage import ModelStorage MODEL_DIRPATH = os.getenv("MODEL_DIRPATH", default="tweet_classifier/models/logistic_regression/2020-09-08-1229") if __name__ == "__main__": storage = ModelStorage(dirpath=MODEL_DIRPATH) storage.promote_model()
281
22.5
113
py
tweet-analysis-2020
tweet-analysis-2020-main/app/nlp/model_storage.py
import os import pickle import json from pprint import pprint from shutil import copytree from memory_profiler import profile from app import DATA_DIR, seek_confirmation from app.file_storage import FileStorage from app.decorators.datetime_decorators import logstamp MODELS_DIRPATH = "tweet_classifier/models" # os.pa...
5,211
32.197452
120
py
tweet-analysis-2020
tweet-analysis-2020-main/app/nlp/bulk_predict.py
import os from app import seek_confirmation from app.job import Job from app.bq_service import BigQueryService from app.nlp.model_storage import ModelStorage, MODELS_DIRPATH MODEL_NAME = os.getenv("MODEL_NAME", default="current_best") LIMIT = os.getenv("LIMIT") BATCH_SIZE = int(os.getenv("BATCH_SIZE", default="10000...
1,743
29.596491
108
py
tweet-analysis-2020
tweet-analysis-2020-main/app/nlp/model_training.py
import os from datetime import datetime from pprint import pprint from pandas import DataFrame from sklearn.model_selection import train_test_split from sklearn.metrics import classification_report # accuracy_score from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.linear_model import LogisticR...
4,403
35.098361
138
py
tweet-analysis-2020
tweet-analysis-2020-main/app/nlp/client.py
import os from app.nlp.model_storage import ModelStorage, BEST_MODEL_DIRPATH if __name__ == "__main__": storage = ModelStorage(dirpath=BEST_MODEL_DIRPATH) tv = storage.load_vectorizer() print(type(tv)) print("FEATURES / TOKENS:", len(tv.get_feature_names())) #> 3842 clf = storage.load_model() ...
649
22.214286
68
py
tweet-analysis-2020
tweet-analysis-2020-main/app/nlp/basilica/embedder.py
import os from app.decorators.datetime_decorators import logstamp from app.job import Job from app.bq_service import BigQueryService from app.nlp.basilica.service import BasilicaService MIN_VAL = float(os.getenv("MIN_VAL", default="0.0")) MAX_VAL = float(os.getenv("MAX_VAL", default="1.0")) LIMIT = os.getenv("LIMIT")...
2,164
30.376812
157
py
tweet-analysis-2020
tweet-analysis-2020-main/app/nlp/basilica/embedder_parallel.py
import os from concurrent.futures import ThreadPoolExecutor, as_completed from threading import current_thread #, #Thread, Lock, BoundedSemaphore from app.job import Job from app.decorators.datetime_decorators import logstamp from app.bq_service import BigQueryService, split_into_batches from app.nlp.basilica.service ...
2,381
31.630137
123
py
tweet-analysis-2020
tweet-analysis-2020-main/app/nlp/basilica/service.py
import basilica import os from dotenv import load_dotenv load_dotenv() API_KEY = os.getenv("BASILICA_API_KEY") class BasilicaService: def __init__(self): self.client = basilica.Connection(API_KEY) print("-------------------------") print("BASILICA SERVICE...") print(" CLIENT:"...
1,272
26.673913
110
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_collection/twitter_scraper.py
import os from pprint import pprint from http.cookiejar import CookieJar import urllib from dotenv import load_dotenv from bs4 import BeautifulSoup load_dotenv() SCREEN_NAME = os.getenv("SCREEN_NAME", default="s2t2") MAX_FRIENDS = int(os.getenv("MAX_FRIENDS", default=2000)) # the max number of friends to fetch per ...
4,069
35.666667
137
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_collection/investigate_threadpool_executor.py
# super h/t: https://www.youtube.com/watch?v=IEEhzQoKtQU import os import time import random from dotenv import load_dotenv from concurrent.futures import ThreadPoolExecutor, as_completed # see: https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor from threading import Threa...
2,319
37.032787
166
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_collection/twint_scraper.py
# import os # from pprint import pprint # # import twint # from dotenv import load_dotenv # # load_dotenv() # # SCREEN_NAME = os.getenv("TWITTER_SCREEN_NAME", default="elonmusk") # just one to use for testing purposes # VERBOSE = (os.getenv("VERBOSE_SCRAPER", default="false") == "true") # set like... VERBOSE_SCRAPER=...
2,169
35.166667
108
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_collection/twitter_service.py
# import os # from pprint import pprint # from dotenv import load_dotenv # import tweepy # # load_dotenv() # # CONSUMER_KEY = os.getenv("TWITTER_CONSUMER_KEY", default="OOPS") # CONSUMER_SECRET = os.getenv("TWITTER_CONSUMER_SECRET", default="OOPS") # ACCESS_KEY = os.getenv("TWITTER_ACCESS_TOKEN", default="OOPS") # ACC...
3,855
36.076923
121
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_collection/batch_per_thread.py
import time from threading import current_thread, BoundedSemaphore from concurrent.futures import ThreadPoolExecutor #, as_completed from app import SERVER_NAME, SERVER_DASHBOARD_URL from app.email_service import send_email from app.friend_collection import (MAX_THREADS, BATCH_SIZE, LIMIT, MIN_ID, MAX_ID, user_wi...
2,328
35.390625
106
py
tweet-analysis-2020
tweet-analysis-2020-main/app/friend_collection/__init__.py
import os from datetime import datetime from dotenv import load_dotenv from threading import current_thread, BoundedSemaphore from concurrent.futures import ThreadPoolExecutor, as_completed # see: https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor from app import APP_ENV f...
4,005
42.075269
166
py
tweet-analysis-2020
tweet-analysis-2020-main/app/botcode/mpi_cluster_manager.py
#import os #from pprint import pprint # #from mpi4py import MPI #import numpy as np #from networkx import DiGraph # #class ClusterManager: # def __init__(self): # self.node_name = MPI.Get_processor_name() # self.intracomm = MPI.COMM_WORLD # # def inspect(self): # print("-------------------...
1,583
28.886792
123
py
tweet-analysis-2020
tweet-analysis-2020-main/app/botcode/classifier.py
import os from pandas import DataFrame from app.friend_graphs.graph_analyzer import GraphAnalyzer from app.decorators.number_decorators import fmt_n, fmt_pct from app.botcode.investigation import classify_bot_probabilities if __name__ == "__main__": manager = GraphAnalyzer() retweet_graph = manager.graph...
1,469
34
89
py
tweet-analysis-2020
tweet-analysis-2020-main/app/botcode/network_classifier_helper.py
# # AN ADAPTATION OF THE ORIGINAL BOTCODE (SEE THE "START" DIR) # import os from dotenv import load_dotenv import numpy as np from networkx import DiGraph, minimum_cut # load_dotenv() # HYPERPARAMETERS MU = float(os.getenv("MU", default="1")) # called "gamma" in the paper ALPHA_1 = float(os.getenv("ALPHA_1", def...
9,650
32.27931
229
py
tweet-analysis-2020
tweet-analysis-2020-main/app/botcode/investigation.py
import os from pprint import pprint import numpy as np from networkx import DiGraph from app.botcode.network_classifier_helper import parse_bidirectional_links, compute_link_energy, compile_energy_graph from app.decorators.number_decorators import fmt_n from conftest import compile_mock_rt_graph def classify_bot_...
4,946
40.225
129
py
tweet-analysis-2020
tweet-analysis-2020-main/app/tweet_recollection/collector.py
import os from pprint import pprint from functools import lru_cache from dotenv import load_dotenv from app import seek_confirmation, server_sleep from app.bq_service import BigQueryService, split_into_batches, generate_timestamp from app.twitter_service import TwitterService from app.tweet_recollection.parser impor...
5,169
42.445378
248
py
tweet-analysis-2020
tweet-analysis-2020-main/app/tweet_recollection/parser.py
def parse_full_text(status): """Param status (tweepy.models.Status)""" return clean_text(status.full_text) def clean_text(my_str): """Removes line-breaks for cleaner CSV storage. Handles string or null value. Returns string or null value Param my_str (str) """ try: my_str...
489
23.5
81
py
tweet-analysis-2020
tweet-analysis-2020-main/app/ks_test/impeachment_topic_pair_analyzers.py
import os from pprint import pprint from itertools import combinations from pandas import read_csv from app.ks_test.topic_pair_analyzer import TopicPairAnalyzer, RESULTS_CSV_FILEPATH from app.ks_test.impeachment_topics import IMPEACHMENT_TOPICS # todo: allow customization of topics list via CSV file if __name__ == ...
1,187
33.941176
117
py
tweet-analysis-2020
tweet-analysis-2020-main/app/ks_test/interpreter.py
import os from dotenv import load_dotenv load_dotenv() PVAL_MAX = float(os.getenv("PVAL_MAX", default="0.01")) # the maximum pvalue under which to reject the ks test null hypothesis def interpret(ks_test_result, pval_max=PVAL_MAX): """ Interprets the results of a KS test, indicates whether or not to reject...
1,008
33.793103
126
py
tweet-analysis-2020
tweet-analysis-2020-main/app/ks_test/topic_analyzer.py
import os from functools import lru_cache from pprint import pprint from dotenv import load_dotenv import numpy as np from scipy.stats import ks_2samp from pandas import DataFrame, read_csv, concat from app import DATA_DIR from app.decorators.datetime_decorators import to_ts, fmt_date from app.bq_service import BigQ...
4,138
30.838462
118
py
tweet-analysis-2020
tweet-analysis-2020-main/app/ks_test/impeachment_topic_analyzers.py
import os from pprint import pprint from pandas import read_csv from app.ks_test.topic_analyzer import TopicAnalyzer, RESULTS_CSV_FILEPATH from app.ks_test.impeachment_topics import IMPEACHMENT_TOPICS # todo: allow customization of topics list via CSV file if __name__ == "__main__": if os.path.isfile(RESULTS_C...
1,055
34.2
117
py
tweet-analysis-2020
tweet-analysis-2020-main/app/ks_test/topic_pair_analyzer.py
import os from pprint import pprint from functools import lru_cache from dotenv import load_dotenv from app import DATA_DIR from app.decorators.datetime_decorators import to_ts from app.ks_test.topic_analyzer import TopicAnalyzer load_dotenv() X_TOPIC = os.getenv("X_TOPIC", default="#MAGA") Y_TOPIC = os.getenv("Y_...
2,565
35.140845
148
py
tweet-analysis-2020
tweet-analysis-2020-main/app/ks_test/investigation.py
import numpy as np from scipy.stats import kstest, ks_2samp np.random.seed(2020) if __name__ == "__main__": # np.random.normal(center, spread, size) x = np.random.normal(0, 1, 10) y = np.random.normal(0, 1, 10) z = np.random.normal(1.1, 0.9, 10) # one of these things is not like the other print...
1,560
46.30303
152
py
tweet-analysis-2020
tweet-analysis-2020-main/app/ks_test/impeachment_topics.py
# todo: allow customization of topics list via CSV file IMPEACHMENT_TOPICS = [ # TAGS "#MAGA", # "#IGHearing", -- very small sample size "#ImpeachAndConvict", "#TrumpImpeachment", ##"#IGReport", ##"#SenateHearing", ##"#FactsMatter", ##"#ImpeachmentRally", ##"#ImpeachmentEve", ...
1,357
20.903226
65
py
tweet-analysis-2020
tweet-analysis-2020-main/app/decorators/number_decorators.py
def fmt_n(large_number): """ Formats a large number with thousands separator, for printing and logging. Param large_number (int) like 1_000_000_000 Returns (str) like '1,000,000,000' """ return f"{large_number:,.0f}" def fmt_pct(decimal_number): """ Formats a large number with th...
502
19.12
78
py
tweet-analysis-2020
tweet-analysis-2020-main/app/decorators/datetime_decorators.py
from datetime import datetime, timezone def logstamp(): """ Formats current timestamp, for printing and logging. """ return dt_to_s(datetime.now()) # # DATETIME DECORATORS # def dt_to_s(dt): """ Converts datetime object to date string like "2020-01-01 00:00:00" Params: dt (datetime) lik...
2,136
23.848837
144
py
tweet-analysis-2020
tweet-analysis-2020-main/app/tweet_collection_v2/bq_migrations.py
from pprint import pprint from app import seek_confirmation from app.decorators.datetime_decorators import dt_to_s from app.bq_service import BigQueryService from app.tweet_collection_v2.csv_storage import LocalStorageService if __name__ == "__main__": bq_service = BigQueryService() # TOPICS bq_servi...
881
25.727273
136
py
tweet-analysis-2020
tweet-analysis-2020-main/app/tweet_collection_v2/tweet_parser.py
from app.decorators.datetime_decorators import dt_to_s def parse_status(status): """ Param status (tweepy.models.Status) Converts a nested status structure into a flat row of non-normalized status and user attributes. """ if hasattr(status, "retweeted_status") and status.retweeted_status: ...
2,316
31.180556
107
py
tweet-analysis-2020
tweet-analysis-2020-main/app/tweet_collection_v2/stream_listener.py
import os from pprint import pprint from time import sleep from dotenv import load_dotenv from tweepy.streaming import StreamListener from tweepy import Stream from urllib3.exceptions import ProtocolError from app import seek_confirmation from app.twitter_service import TwitterService from app.bq_service import BigQ...
5,598
32.526946
128
py
tweet-analysis-2020
tweet-analysis-2020-main/app/tweet_collection_v2/csv_storage.py
import os from dotenv import load_dotenv from pandas import DataFrame, read_csv, concat from app import DATA_DIR, seek_confirmation load_dotenv() EVENT_NAME = os.getenv("EVENT_NAME", default="impeachment") class LocalStorageService: """ Must have same methods and params as the remote version - see append...
2,379
34.522388
120
py
tweet-analysis-2020
tweet-analysis-2020-main/app/botcode_v2/classifier.py
import os import datetime import time from functools import lru_cache from dotenv import load_dotenv import numpy as np from pandas import DataFrame import matplotlib.pyplot as plt from conftest import compile_mock_rt_graph from app import APP_ENV from app.decorators.number_decorators import fmt_n, fmt_pct from app....
8,235
35.767857
185
py
tweet-analysis-2020
tweet-analysis-2020-main/app/botcode_v2/network_classifier_helper.py
# # A NEAR REPLICA OF BOTCODE VERSION 2 (SEE THE "START" DIR) # import math from collections import defaultdict from operator import itemgetter import time from datetime import datetime import numpy as np import networkx as nx ########################################################################## ##############...
8,570
33.011905
121
py
tweet-analysis-2020
tweet-analysis-2020-main/app/botcode_v2/investigation.py
import os import datetime import time from dotenv import load_dotenv import numpy as np from pandas import DataFrame import matplotlib.pyplot as plt #from sklearn import metrics #from scipy.sparse import csc_matrix from conftest import compile_mock_rt_graph from app.decorators.number_decorators import fmt_n, fmt_pct...
4,726
29.496774
178
py
tweet-analysis-2020
tweet-analysis-2020-main/app/toxicity/checkpoint_scorer.py
import os from functools import lru_cache #from pprint import pprint import gc from dotenv import load_dotenv from app import server_sleep, seek_confirmation from app.decorators.number_decorators import fmt_n from app.bq_service import BigQueryService, generate_timestamp, split_into_batches from app.toxicity.model...
4,743
31.272109
197
py
tweet-analysis-2020
tweet-analysis-2020-main/app/toxicity/model_manager.py
# # adapted from: https://github.com/unitaryai/detoxify/blob/master/detoxify/detoxify.py # # using the pre-trained toxicity models provided via Detoxify checkpoints, but... # 1) let's try different / lighter torch requirement approaches (to enable installation on heroku) - see requirements.txt file # 2) let's also try...
6,115
39.773333
155
py
tweet-analysis-2020
tweet-analysis-2020-main/app/toxicity/scorer_async.py
import os from threading import current_thread, BoundedSemaphore from concurrent.futures import ThreadPoolExecutor, as_completed # see: https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor from dotenv import load_dotenv from app import server_sleep from app.decorators.numbe...
2,081
32.580645
166
py
tweet-analysis-2020
tweet-analysis-2020-main/app/toxicity/investigate_models.py
from pprint import pprint from detoxify import Detoxify from pandas import DataFrame if __name__ == '__main__': texts = [ "RT @realDonaldTrump: I was very surprised & disappointed that Senator Joe Manchin of West Virginia voted against me on the Democrat’s total…", "RT @realDonaldTrump: Craz...
1,583
38.6
155
py
tweet-analysis-2020
tweet-analysis-2020-main/app/toxicity/scorer.py
import os from functools import lru_cache #from pprint import pprint from dotenv import load_dotenv from detoxify import Detoxify from pandas import DataFrame from app import server_sleep from app.decorators.number_decorators import fmt_n from app.bq_service import BigQueryService, generate_timestamp, split_into_bat...
5,428
35.436242
171
py
tweet-analysis-2020
tweet-analysis-2020-main/app/toxicity/investigate_benchmarks.py
from time import perf_counter # see: https://stackoverflow.com/questions/25785243/understanding-time-perf-counter-and-time-process-time from functools import wraps from detoxify import Detoxify def performance_timer(func): """ Wrap your function in this decorator to see how long it takes. Returns the dur...
1,494
25.696429
135
py
tweet-analysis-2020
tweet-analysis-2020-main/app/toxicity/checkpoint_scorer_async.py
import os from threading import current_thread #, BoundedSemaphore from concurrent.futures import ThreadPoolExecutor, as_completed # see: https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor import gc from dotenv import load_dotenv from app import server_sleep from app.deco...
2,172
31.924242
166
py
tweet-analysis-2020
tweet-analysis-2020-main/app/retweet_graphs_v2/graph_storage.py
import os import json import pickle from sys import getsizeof from memory_profiler import profile #, memory_usage from pprint import pprint from pandas import DataFrame from networkx import write_gpickle, read_gpickle from dotenv import load_dotenv from conftest import compile_mock_rt_graph from app import DATA_DIR,...
8,149
31.213439
154
py
tweet-analysis-2020
tweet-analysis-2020-main/app/retweet_graphs_v2/retweet_grapher.py
import os from datetime import datetime import time from memory_profiler import profile from dotenv import load_dotenv from networkx import DiGraph from conftest import compile_mock_rt_graph from app import APP_ENV, DATA_DIR, SERVER_NAME, SERVER_DASHBOARD_URL, seek_confirmation from app.decorators.number_decorators ...
4,571
35.285714
322
py
tweet-analysis-2020
tweet-analysis-2020-main/app/retweet_graphs_v2/job.py
import time from app.decorators.number_decorators import fmt_n class Job(): def __init__(self): self.start_at = None self.end_at = None self.duration_seconds = None self.counter = 0 # represents the number of items processed def start(self): print("-----------------")...
935
26.529412
111
py
tweet-analysis-2020
tweet-analysis-2020-main/app/retweet_graphs_v2/prep/lookup_user_ids.py
import os import json from tweepy.error import TweepError from pandas import DataFrame from dotenv import load_dotenv from app import DATA_DIR, seek_confirmation from app.decorators.datetime_decorators import logstamp from app.bq_service import BigQueryService from app.twitter_service import TwitterService load_dot...
2,114
32.046875
187
py