-
Notifications
You must be signed in to change notification settings - Fork 0
/
w.py
43 lines (35 loc) · 1.41 KB
/
w.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
import json
from datetime import datetime
from collections import defaultdict
from pathlib import Path # Import Path from pathlib
def extract_timestamp_from_filename(filename):
# Extract timestamp from the filename (e.g., 231110051045)
timestamp_str = filename[:12]
timestamp = datetime.strptime(timestamp_str, "%y%m%d%H%M%S")
return timestamp
def find_earliest_timestamp(files):
url_timestamps = defaultdict(lambda: datetime.max)
for file in files:
with open(file, 'r') as f:
data = json.load(f)
timestamp = extract_timestamp_from_filename(file.name)
for url in data:
url_timestamps[url] = min(url_timestamps[url], timestamp)
return url_timestamps
def main():
directory = "./" # Change this to the directory containing your files
files = [file for file in Path(directory).iterdir() if file.is_file() and file.name.endswith('.json')]
url_timestamps = find_earliest_timestamp(files)
current_date = None
count = 1
for url, timestamp in url_timestamps.items():
date_str = timestamp.strftime("%Y-%m-%d")
if date_str != current_date:
if current_date is not None:
print("---")
print(f"\nAdded on {date_str}:")
current_date = date_str
print(f"{count} ![Image {len(url_timestamps)}]({url})")
count = count+1
if __name__ == "__main__":
main()