-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathflickr_report.py
executable file
·144 lines (117 loc) · 3.41 KB
/
flickr_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python
"""
This file is dedicated to visualizing the data collected for Flickr.
"""
# Standard library
import argparse
import os
import sys
import traceback
from datetime import datetime, timezone
# Third-party
# import matplotlib.pyplot as plt
# import matplotlib.ticker as ticker
import pandas as pd
# import seaborn as sns
from pandas import PeriodIndex
# Add parent directory so shared can be imported
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
# First-party/Local
import shared # noqa: E402
# Setup
LOGGER, PATHS = shared.setup(__file__)
def parse_arguments():
"""
Parses command-line arguments, returns parsed arguments.
"""
LOGGER.info("Parsing command-line arguments")
# Taken from shared module, fix later
datetime_today = datetime.now(timezone.utc)
quarter = PeriodIndex([datetime_today.date()], freq="Q")[0]
parser = argparse.ArgumentParser(description="Flickr Report")
parser.add_argument(
"--quarter",
"-q",
type=str,
required=False,
default=f"{quarter}",
help="Data quarter in format YYYYQx, e.g., 2024Q2",
)
parser.add_argument(
"--skip-commit",
action="store_true",
help="Don't git commit changes (also skips git push changes)",
)
parser.add_argument(
"--skip-push",
action="store_true",
help="Don't git push changes",
)
parser.add_argument(
"--show-plots",
action="store_true",
help="Show generated plots (in addition to saving them)",
)
args = parser.parse_args()
if args.skip_commit:
args.skip_push = True
return args
def load_data(args):
"""
Load the collected data from the CSV file.
"""
selected_quarter = args.quarter
file_path = os.path.join(
PATHS["data"],
f"{selected_quarter}",
"1-fetch",
"flickr_fetched",
"final.csv",
)
if not os.path.exists(file_path):
LOGGER.error(f"Data file not found: {file_path}")
return pd.DataFrame()
data = pd.read_csv(file_path)
LOGGER.info(f"Data loaded from {file_path}")
return data
# Add functions for individual license graphs + word clouds + total license
def main():
# Fetch and merge changes
shared.fetch_and_merge(PATHS["repo"])
args = parse_arguments()
data = load_data(args)
if data.empty:
return
current_directory = os.getcwd()
LOGGER.info(f"Current working directory: {current_directory}")
"""
Insert functions for Flickr
"""
# Add and commit changes
if not args.skip_commit:
shared.add_and_commit(
PATHS["repo"],
PATHS["data_quarter"],
"Add and commit new GitHub reports",
)
# Push changes
if not args.skip_push:
shared.push_changes(PATHS["repo"])
if __name__ == "__main__":
try:
main()
except shared.QuantifyingException as e:
if e.exit_code == 0:
LOGGER.info(e.message)
else:
LOGGER.error(e.message)
sys.exit(e.exit_code)
except SystemExit as e:
LOGGER.error(f"System exit with code: {e.code}")
sys.exit(e.code)
except KeyboardInterrupt:
LOGGER.info("(130) Halted via KeyboardInterrupt.")
sys.exit(130)
except Exception:
LOGGER.exception(f"(1) Unhandled exception: {traceback.format_exc()}")
sys.exit(1)