-
Notifications
You must be signed in to change notification settings - Fork 4
Split fetch and parse for users and rework the cache to support it. #306
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
Open
abergeron
wants to merge
15
commits into
master
Choose a base branch
from
user_cache
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4ebec26
Make new cache class and rename the old one
abergeron 76e9d05
Improve the new cache and try to use it.
abergeron 2524d5e
Remove the config parameter from the parse method in user plugins
abergeron ca3912f
Rework the cache to be able to save sessions that have multiple key-v…
abergeron 9255a2e
add tests for the new cache
abergeron bb4f960
Fix command-line
abergeron 129fedf
Remove users subcommand from acquire
abergeron 4e4e477
Fix obvious errors
abergeron f4a2ca4
Update the scrape_users test to use the new functions
abergeron f963479
Rework the cache traversal code to be more robust
abergeron a3a53bd
Fix the tests for the user plugins following the removal of the confi…
abergeron c46bfef
Make cache_entry use a context manager to make sure that people don't…
abergeron 1dbe634
Fix invalid scraper test
abergeron 188991a
Expose multiple values for the same key in the interface
abergeron ca9052f
Fix bug in cache traversal that could ignore entries.
abergeron 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 was deleted.
Oops, something went wrong.
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,18 @@ | ||
| from dataclasses import dataclass | ||
| from typing import Union | ||
|
|
||
| from simple_parsing import subparsers | ||
|
|
||
| from .users import FetchUsers | ||
|
|
||
|
|
||
| @dataclass | ||
| class Fetch: | ||
| command: Union[FetchUsers] = subparsers( | ||
| { | ||
| "users": FetchUsers, | ||
| } | ||
| ) | ||
|
|
||
| def execute(self) -> int: | ||
| return self.command.execute() |
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,21 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| from simple_parsing import field | ||
|
|
||
| from sarc.config import config | ||
| from sarc.core.scraping.users import fetch_users | ||
|
|
||
|
|
||
| @dataclass | ||
| class FetchUsers: | ||
| force: bool = field( | ||
| action="store_true", | ||
| help="Force recalculating the data rather than use the cache", | ||
| ) | ||
|
|
||
| def execute(self) -> int: | ||
| users_cfg = config("scraping").users | ||
| assert users_cfg is not None | ||
|
|
||
| fetch_users(list(users_cfg.scrapers.items())) | ||
| return 0 |
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,18 @@ | ||
| from dataclasses import dataclass | ||
| from typing import Union | ||
|
|
||
| from simple_parsing import subparsers | ||
|
|
||
| from .users import ParseUsers | ||
|
|
||
|
|
||
| @dataclass | ||
| class Parse: | ||
| command: Union[ParseUsers] = subparsers( | ||
| { | ||
| "users": ParseUsers, | ||
| } | ||
| ) | ||
|
|
||
| def execute(self) -> int: | ||
| return self.command.execute() |
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,19 @@ | ||
| from dataclasses import dataclass | ||
| from datetime import datetime | ||
|
|
||
| from simple_parsing import field | ||
|
|
||
| from sarc.core.scraping.users import parse_users | ||
| from sarc.users.db import get_user_collection | ||
|
|
||
|
|
||
| @dataclass | ||
| class ParseUsers: | ||
| from_: datetime = field(help="Start parsing the cache from the specified date") | ||
|
|
||
| def execute(self) -> int: | ||
| coll = get_user_collection() | ||
| for um in parse_users(from_=self.from_): | ||
| coll.update_user(um) | ||
|
|
||
| return 0 |
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.