-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_readme.py
29 lines (21 loc) · 984 Bytes
/
update_readme.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
from pymongo import MongoClient
import os
def update_readme():
# Fetch MongoDB connection details from GitHub secrets
mongo_connection_string = os.environ['MONGO_CONNECTION_STRING']
mongo_database_name = os.environ['MONGO_DATABASE_NAME']
mongo_collection_name = os.environ['MONGO_COLLECTION_NAME']
client = MongoClient(mongo_connection_string)
db = client[mongo_database_name]
collection = db[mongo_collection_name]
num_movies = collection.count_documents({})
with open("README.md", "r") as readme_file:
readme_content = readme_file.read()
updated_readme_content = readme_content.replace(
"**Number of movies currently:** (updated daily)", f"**Number of movies currently:** {num_movies} (updated daily)"
)
with open("README.md", "w") as readme_file:
readme_file.write(updated_readme_content)
print(f"Number of movies currently: {num_movies}")
if __name__ == "__main__":
update_readme()