mirror of
https://github.com/bellingcat/tiktok-hashtag-analysis.git
synced 2026-06-12 21:38:30 +03:00
Merge branch 'main' of https://github.com/bellingcat/tiktok_hashtag_analysis into main
This commit is contained in:
@@ -2,10 +2,13 @@ import os, sys
|
||||
import csv, json
|
||||
import argparse
|
||||
import matplotlib.pyplot as plt
|
||||
<<<<<<< HEAD
|
||||
from datetime import datetime
|
||||
|
||||
sys.path.insert(0, '../tiktok_downloader')
|
||||
import file_methods, global_data
|
||||
=======
|
||||
>>>>>>> bfa90676f121dd88e070dc134791a596a104e784
|
||||
|
||||
|
||||
|
||||
@@ -46,6 +49,7 @@ def get_occurrences(filename, n=1 , sort=True):
|
||||
|
||||
|
||||
|
||||
<<<<<<< HEAD
|
||||
def plot(n, length, k, v, img_folder):
|
||||
plt.scatter(k, v)
|
||||
plt.tight_layout()
|
||||
@@ -55,6 +59,15 @@ def plot(n, length, k, v, img_folder):
|
||||
plt.ylabel(f'Number of occurrences')
|
||||
save_plot(plt, img_folder)
|
||||
plt.show(block=None)
|
||||
=======
|
||||
def plot(n, length, k, v):
|
||||
plt.scatter(k, v)
|
||||
plt.tight_layout()
|
||||
plt.title(f'Hashtag Distribution')
|
||||
plt.xlabel(f'Top {n} hashtags from {length} posts.')
|
||||
plt.ylabel(f'Number of occurrences')
|
||||
plt.show()
|
||||
>>>>>>> bfa90676f121dd88e070dc134791a596a104e784
|
||||
return
|
||||
|
||||
|
||||
@@ -71,6 +84,7 @@ def print_occurrences(l, k, v):
|
||||
return
|
||||
|
||||
|
||||
<<<<<<< HEAD
|
||||
def save_plot(plt, img_folder):
|
||||
try:
|
||||
now = datetime.now()
|
||||
@@ -85,6 +99,10 @@ def save_plot(plt, img_folder):
|
||||
if __name__ == "__main__":
|
||||
img_folder = global_data.IMAGES
|
||||
file_methods.check_file(img_folder, "dir")
|
||||
=======
|
||||
|
||||
if __name__ == "__main__":
|
||||
>>>>>>> bfa90676f121dd88e070dc134791a596a104e784
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("input_file", help="The json hashtag file name")
|
||||
parser.add_argument("n", help="The number of top n occurrences", type=int)
|
||||
@@ -100,7 +118,11 @@ if __name__ == "__main__":
|
||||
path = f"./{base}_sorted_hashtags.csv"
|
||||
if args.plot:
|
||||
length, keys, values = get_occurrences(args.input_file, args.n)
|
||||
<<<<<<< HEAD
|
||||
plot(args.n, length, keys, values, img_folder)
|
||||
=======
|
||||
plot(args.n, length, keys, values)
|
||||
>>>>>>> bfa90676f121dd88e070dc134791a596a104e784
|
||||
else:
|
||||
length, keys, values = get_occurrences(args.input_file, args.n)
|
||||
print_occurrences(length, keys, values)
|
||||
|
||||
Reference in New Issue
Block a user