-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into upload-thorttling
- Loading branch information
Showing
15 changed files
with
130 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ jobs: | |
run-pytest: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
|
@@ -41,7 +41,7 @@ jobs: | |
with: | ||
files: junit/**/*.xml | ||
- name: Upload coverage to Codecov | ||
uses: codecov/[email protected].3 | ||
uses: codecov/[email protected].4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
files: ./coverage.xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import argparse | ||
from google.cloud import firestore | ||
from datetime import datetime, timedelta | ||
DELETE_BATCH_SIZE = 200 | ||
STORE_NAME = "error_reports" | ||
|
||
|
||
def delete_old_data(): | ||
# Initialize Firestore | ||
db = firestore.Client() | ||
collection_ref = db.collection(STORE_NAME) | ||
|
||
# Define the datetime for one week ago | ||
week_ago = datetime.now() - timedelta(days=7) | ||
|
||
# Query to find all documents older than a week | ||
total_deleted = 0 | ||
while True: | ||
to_delete = 0 | ||
batch = db.batch() | ||
docs = collection_ref.where('server_time', '<', week_ago).stream() | ||
for doc in docs: | ||
to_delete += 1 | ||
batch.delete(doc.reference) | ||
if to_delete >= DELETE_BATCH_SIZE: | ||
break | ||
if to_delete > 0: | ||
batch.commit() | ||
total_deleted += to_delete | ||
print(f"Deleted {to_delete} documents ({total_deleted} total)") | ||
else: | ||
break | ||
print(f"Success: All documents older than a week deleted ({total_deleted} total)") | ||
|
||
|
||
def main(): | ||
# Create command line argument parser | ||
parser = argparse.ArgumentParser() | ||
|
||
# Add purge argument | ||
parser.add_argument("--purge", help="Delete all documents older than a week.", action="store_true") | ||
|
||
# Add any other argument you want in future. For example: | ||
# parser.add_argument("--future_arg", help="Perform some future operation.") | ||
|
||
args = parser.parse_args() | ||
|
||
# Respond to arguments | ||
if args.purge: | ||
confirm = input('Are you sure you want to delete all documents older than a week? (y/n): ') | ||
if confirm.lower() == 'y': | ||
delete_old_data() | ||
else: | ||
print("Abort: No documents were deleted.") | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build: | ||
docker: | ||
web: hassio-google-drive-backup/Dockerfile-server |