-
Notifications
You must be signed in to change notification settings - Fork 48
Spruce up project a bit #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
334799b
Bump version to 0.2.7
gvanrossum-ms 0ee1278
Point to docs
gvanrossum-ms 260b2a6
Rename Homepage to GitHub-repo
gvanrossum-ms 09e6afc
Add fledgling docs/README.md
gvanrossum-ms b2e8fb7
Point docs to docs/README.md
gvanrossum-ms 3037058
Point to docs/ in toplevel README.md
gvanrossum-ms 6e91b95
Rename GitHub-repo to just GitHub
gvanrossum-ms 32b9406
Check and format gmail/
gvanrossum-ms c21e7a5
Update uv.lock
gvanrossum-ms 8aa555d
Add command line argument for maxResults; format with black
gvanrossum-ms 046e01b
Tweak AGENTS.md
gvanrossum-ms 582386d
Tweak TADA.md
gvanrossum-ms 5f45cab
Mature gmail_dump.py script
gvanrossum-ms c7167a3
Tweak TADA.md
gvanrossum-ms 3585083
Respond to Rob's review
gvanrossum-ms d790039
Ignore *_dump folders anywhere
gvanrossum-ms de11e5c
Add gmail instructions to documentation list in TADA.md
gvanrossum-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,14 @@ | ||
| # Typeagent docs | ||
|
|
||
| ## TBD | ||
|
|
||
| For now we have: | ||
|
|
||
| ### High-level API: | ||
|
|
||
| - create_conversation | ||
| - [conversation.query](query-method.md) | ||
|
|
||
| ### Other | ||
|
|
||
| - [architecture design](typeagent-architecture.md) |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,29 +1,85 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from pathlib import Path | ||
| import argparse | ||
| import time | ||
| from base64 import urlsafe_b64decode as b64d | ||
| from pathlib import Path | ||
|
|
||
| from google.oauth2.credentials import Credentials | ||
gvanrossum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from google_auth_oauthlib.flow import InstalledAppFlow | ||
| from googleapiclient.discovery import build | ||
| from google.oauth2.credentials import Credentials | ||
|
|
||
| SCOPES = ["https://www.googleapis.com/auth/gmail.readonly"] | ||
| CREDS = "client_secret.json" | ||
| TOKEN = Path("token.json") | ||
| OUT = Path("mail_dump"); OUT.mkdir(exist_ok=True) | ||
|
|
||
| def get_creds(): | ||
| if TOKEN.exists(): | ||
| return Credentials.from_authorized_user_file(TOKEN, SCOPES) | ||
| flow = InstalledAppFlow.from_client_secrets_file(CREDS, SCOPES) | ||
| OUT = Path("mail_dump") | ||
gvanrossum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def get_creds(creds_dir: Path): | ||
| token_file = creds_dir / "token.json" | ||
| client_secret_file = creds_dir / "client_secret.json" | ||
|
|
||
| if token_file.exists(): | ||
| return Credentials.from_authorized_user_file(token_file, SCOPES) | ||
| flow = InstalledAppFlow.from_client_secrets_file(client_secret_file, SCOPES) | ||
| creds = flow.run_local_server(port=0) | ||
| TOKEN.write_text(creds.to_json()) | ||
| token_file.write_text(creds.to_json()) | ||
| return creds | ||
|
|
||
| svc = build("gmail", "v1", credentials=get_creds()) | ||
|
|
||
| resp = svc.users().messages().list(userId="me", maxResults=50, q="").execute() | ||
| for m in resp.get("messages", []): | ||
| raw = svc.users().messages().get(userId="me", id=m["id"], format="raw").execute()["raw"] | ||
| Path(OUT / f"{m['id']}.eml").write_bytes(b64d(raw.encode())) | ||
| print("Done.") | ||
| def main(): | ||
| parser = argparse.ArgumentParser( | ||
| description="Download Gmail messages as .eml files" | ||
| ) | ||
| parser.add_argument( | ||
| "--max-results", | ||
| type=int, | ||
| default=50, | ||
| help="Maximum number of messages to download (default: 50)", | ||
| ) | ||
| parser.add_argument( | ||
| "--output-dir", | ||
| type=Path, | ||
| default=OUT, | ||
| help="Output directory for .eml files (default: mail_dump)", | ||
| ) | ||
| parser.add_argument( | ||
| "--query", | ||
| type=str, | ||
| default="", | ||
| help="Gmail search query (default: empty, returns all messages)", | ||
| ) | ||
| parser.add_argument( | ||
| "--creds-dir", | ||
| type=Path, | ||
| default=Path("."), | ||
| help="Directory containing client_secret.json and token.json (default: current directory)", | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| args.output_dir.mkdir(exist_ok=True) | ||
|
|
||
| svc = build("gmail", "v1", credentials=get_creds(args.creds_dir)) | ||
|
|
||
| start_time = time.time() | ||
| resp = ( | ||
| svc.users() | ||
| .messages() | ||
| .list(userId="me", maxResults=args.max_results, q=args.query) | ||
| .execute() | ||
| ) | ||
| count = 0 | ||
| for m in resp.get("messages", []): | ||
| raw = ( | ||
| svc.users() | ||
| .messages() | ||
| .get(userId="me", id=m["id"], format="raw") | ||
| .execute()["raw"] | ||
| ) | ||
| Path(args.output_dir / f"{m['id']}.eml").write_bytes(b64d(raw.encode())) | ||
| count += 1 | ||
| elapsed = time.time() - start_time | ||
| print(f"Downloaded {count} messages to {args.output_dir} in {elapsed:.1f}s") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.