The Code -> Github Gist
This Gist contains a Python script that commits historical event data to a GitHub repository using backdated commits.
The script performs the following tasks:
- Checks if the GitHub repository exists; if not, it creates the repository.
- Creates an initial commit with a backdated README file.
- Fetches historical events from an external API based on dates.
- Commits each event as a separate backdated commit with the event's date and description.
- Utilizes a persistent state file (
.events_state.json) and a log file (events.log) to resume operations after interruptions. - Optimizes the resume process by parsing the last committed event from the log file.
-
Repository Initialization:
- The script checks for the existence of the target repository using the GitHub API.
- If the repository is empty, an initial commit is created using a temporary local git repository with custom backdated commit dates.
-
Event Fetching & Commit Process:
- For each day in 1970, historical events are fetched concurrently using a
ThreadPoolExecutor. - Each event is committed sequentially with its own backdated commit; the commit message includes the event date and a truncated description.
- For each day in 1970, historical events are fetched concurrently using a
-
Persistent State & Resuming:
- A persistent state is maintained in
.events_state.jsonto track committed events. - The log file (
events.log) records commit operations, enabling fast resume by parsing the last committed event.
- A persistent state is maintained in
-
Diagnostics and Error Handling:
- A diagnostic mode (
--diagnose) is available to inspect repository status, the latest commit details, and GitHub API rate limits.
- A diagnostic mode (
-
Run the Script:
python main.py
-
Run Diagnostics:
python main.py --diagnose~
-
GitHub Settings: The GitHub token, repository owner, and repository name are configured at the top of
main.py. -
Logging and State Files:
events.log: Logs commit operations and status messages..events_state.json: Stores persistent state to support resuming operations.
- Python 3.x
requestslibrary- Standard libraries:
json,hashlib,datetime,concurrent.futures, etc.
- Ensure that the GitHub token is kept secure.
- This script is intended for generating historical commits and should be adapted as needed.
This project is provided "as-is" and may require modifications for production use.