Skip to content

Commit

Permalink
Start 2023 Wrapped (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
avgupta456 authored Nov 19, 2023
1 parent d80e082 commit 97df594
Show file tree
Hide file tree
Showing 47 changed files with 4,879 additions and 3,806 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,15 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.11
- name: Install dependencies
run: |
cd backend
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Sourcery lint
run: |
cd backend
pip install sourcery-cli
sourcery login --token ${{ secrets.SOURCERY_TOKEN }}
sourcery review --check .
env:
sourcery_token: ${{ secrets.SOURCERY_TOKEN }}
- name: Test with unittest
run: |
cd backend
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ backend/.coverage
backend/gcloud_key.json

frontend/.env
.DS_Store
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# GitHub Trends

[![Coverage Status](https://coveralls.io/repos/github/avgupta456/github-trends/badge.svg?t=jQQ3FK)](https://coveralls.io/github/avgupta456/github-trends)

## SPECIAL: GitHub Wrapped

Check out your GitHub Wrapped at `githubtrends.io/wrapped`!

![github-wrapped](https://user-images.githubusercontent.com/16708871/204590479-556eb628-a7bd-45c0-9b35-9171c3891f12.png)


---

## What is GitHub Trends
Expand Down
70 changes: 0 additions & 70 deletions backend/.sourcery.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ Then, just commit on the main branch (Google Cloud Run takes care of the rest)

## Adding a Secret

Update cloudbuild_pub.yaml, cloudbuild_sub.yaml, .env, .env-template, and GCP Cloud Run Trigger Substitution Variables.
Update cloudbuild.yaml, .env, .env-template, and GCP Cloud Run Trigger Substitution Variables.
59 changes: 59 additions & 0 deletions backend/delete_old_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from typing import Any

import asyncio
from dotenv import find_dotenv, load_dotenv
from datetime import datetime

load_dotenv(find_dotenv())

# flake8: noqa E402

from src.constants import API_VERSION
from src.data.mongo.main import USER_MONTHS


def get_filters(cutoff_date: datetime) -> Any:
return {
"$or": [
{"month": {"$lte": cutoff_date}},
{"version": {"$ne": API_VERSION}},
],
}


async def count_old_rows(cutoff_date: datetime) -> int:
filters = get_filters(cutoff_date)
num_rows = len(await USER_MONTHS.find(filters).to_list(length=None)) # type: ignore
return num_rows


async def delete_old_rows(cutoff_date: datetime):
filters = get_filters(cutoff_date)
result = await USER_MONTHS.delete_many(filters) # type: ignore
print(f"Deleted {result.deleted_count} rows")


async def main():
# Replace 'your_date_field' with the actual name of your date field
cutoff_date = datetime(2022, 12, 31)

count = await count_old_rows(cutoff_date)
if count == 0:
print("No rows to delete.")
return

print(f"Found {count} rows to delete.")
print()

confirmation = input("Are you sure you want to delete these rows? (yes/no): ")
if confirmation.lower() != "yes":
print("Operation canceled.")
return

print()
await delete_old_rows(cutoff_date)


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Loading

0 comments on commit 97df594

Please sign in to comment.