-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a3dc754
Showing
26 changed files
with
771 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
concurrency: | ||
group: ci-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install Hatch | ||
uses: pypa/hatch@install | ||
- name: Run Build | ||
run: | | ||
hatch env create | ||
hatch build | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install Hatch | ||
uses: pypa/hatch@install | ||
- name: Run Test | ||
run: | | ||
hatch env create test | ||
hatch test |
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,6 @@ | ||
# Editor | ||
.idea/ | ||
.vscode/ | ||
|
||
# build | ||
dist/ |
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,39 @@ | ||
# CONTRIBUTING | ||
|
||
fymail use [hatch](https://hatch.pypa.io/latest/) to manage the project. Please | ||
[install](https://hatch.pypa.io/latest/install) it before you go ahead. Run command below to install it if you | ||
use `pip` to manage your python packages, or click [here](https://hatch.pypa.io/latest/install) for others | ||
|
||
```shell | ||
pip install hatch | ||
``` | ||
|
||
## Development | ||
|
||
### Setup Environment | ||
|
||
```shell | ||
# create hatch env and install dependence | ||
hatch env create | ||
``` | ||
|
||
## Test | ||
|
||
create test environment only once, | ||
|
||
```shell | ||
hatch env create test | ||
``` | ||
|
||
and run test in the environment | ||
|
||
```shell | ||
hatch test | ||
``` | ||
|
||
## Release | ||
|
||
* Update version: `hatch version <major|minor|micro|release>`, see [hatch version](https://hatch.pypa.io/latest/version/) | ||
for more detail | ||
* Build package: `hatch build`, see [hatch build](https://hatch.pypa.io/latest/build/) for more detail | ||
* Upload package: `hatch publish`, see [hatch publish](https://hatch.pypa.io/latest/publish/) for more detail |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Jay Chung | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,17 @@ | ||
# FyMail | ||
|
||
FyMail is a shortcut for *F*ind *Y*our e*Mail*. It is a simple tool to search for email addresses in a given | ||
account with a given provider. | ||
|
||
## Quick Start | ||
|
||
```py | ||
fymail = FyMail() | ||
email = await fymail.get(iden="zhongjiajie", provider="github", auth=token) | ||
``` | ||
|
||
Two lines to get the email address of a user, see whole example in [tutorial.py](./examples/tutorial.py) | ||
|
||
## Bulk Search | ||
|
||
see whole example in [bulk.py](./examples/bulk.py) |
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,72 @@ | ||
import asyncio | ||
import os | ||
|
||
import aiohttp | ||
|
||
import logging | ||
from fymail import FyMail | ||
|
||
from aiohttp import ClientSession | ||
import time | ||
|
||
logging.basicConfig() | ||
logging.getLogger().setLevel(logging.INFO) | ||
|
||
# Set the environment variable ``FYMAIL_GH_TOKEN`` to your GitHub token | ||
gh_token = os.environ.get("FYMAIL_GH_TOKEN", None) | ||
if not gh_token: | ||
raise ValueError("Please set the environment variable ``FYMAIL_GH_TOKEN``") | ||
|
||
repos = [ | ||
"python/cpython", | ||
"pypa/pip", | ||
] | ||
|
||
session_header = { | ||
"Authorization": f"token {gh_token}", | ||
"X-GitHub-Api-Version": "2022-11-28", | ||
"Accept": "application/vnd.github+json", | ||
} | ||
|
||
|
||
async def get_repo_contributors(session: ClientSession, repo: str, simple: bool = False) -> list[str]: | ||
contributors = [] | ||
url = f"https://api.github.com/repos/{repo}/contributors" | ||
|
||
page = 1 | ||
while True: | ||
async with session.get(url, params={"page": page}) as response: | ||
response.raise_for_status() | ||
data = await response.json() | ||
if not data: | ||
break | ||
contributors.extend([d.get("login") for d in data if "login" in d]) | ||
page += 1 | ||
|
||
# break current loop | ||
if simple: | ||
break | ||
return contributors | ||
|
||
|
||
async def main(): | ||
async with aiohttp.ClientSession() as session: | ||
session.headers.update(session_header) | ||
|
||
fymail = FyMail() | ||
task_emails = [] | ||
contributors = [] | ||
for repo in repos: | ||
contributors.extend(await get_repo_contributors(session, repo, simple=True)) | ||
task_emails.extend([fymail.get(iden=c, provider="github", auth=gh_token) for c in contributors]) | ||
|
||
start = time.perf_counter() | ||
emails = await asyncio.gather(*task_emails) | ||
end = time.perf_counter() | ||
print(list(zip(contributors, emails))) | ||
print(f"Time taken: {end - start:.2f} seconds, " | ||
f"for {len(repos)} repositories and {len(contributors)} github users.") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import asyncio | ||
from fymail import FyMail | ||
import logging | ||
import os | ||
|
||
logging.basicConfig() | ||
logging.getLogger().setLevel(logging.INFO) | ||
|
||
# Set the environment variable ``FYMAIL_GH_TOKEN`` to your GitHub token | ||
gh_token = os.environ.get("FYMAIL_GH_TOKEN", None) | ||
if not gh_token: | ||
raise ValueError("Please set the environment variable ``FYMAIL_GH_TOKEN``") | ||
|
||
|
||
async def main(): | ||
fymail = FyMail() | ||
email = await fymail.get(iden="zhongjiajie", provider="github", auth=gh_token) | ||
print(email) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" | ||
|
||
[project] | ||
name = "fymail" | ||
dynamic = ["version"] | ||
description = 'Find email for giving account in provider' | ||
readme = "README.md" | ||
requires-python = ">=3.8" | ||
license = "MIT" | ||
keywords = [ | ||
"email", | ||
] | ||
authors = [ | ||
{ name = "Jay Chung", email = "[email protected]" }, | ||
] | ||
classifiers = [ | ||
# https://pypi.org/pypi?%3Aaction=list_classifiers | ||
"Development Status :: 1 - Planning", | ||
"Intended Audience :: Developers", | ||
"Operating System :: Unix", | ||
"Operating System :: POSIX", | ||
"Operating System :: Microsoft :: Windows", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
"Programming Language :: Python :: Implementation :: CPython", | ||
"Programming Language :: Python :: Implementation :: PyPy", | ||
"Topic :: Software Development :: User Interfaces", | ||
] | ||
dependencies = [ | ||
"aiohttp>=3.7.4", | ||
] | ||
|
||
[project.urls] | ||
Documentation = "https://github.com/zhongjiajie/fymail#readme" | ||
Issues = "https://github.com/zhongjiajie/fymail/issues" | ||
Source = "https://github.com/zhongjiajie/fymail" | ||
|
||
[tool.hatch.version] | ||
path = "src/fymail/__init__.py" | ||
|
||
[tool.hatch.envs.test] | ||
extra-dependencies = [ | ||
"pytest-asyncio", | ||
] | ||
default-args = ["tests"] | ||
extra-args = ["-vv"] | ||
|
||
[tool.hatch.envs.types] | ||
extra-dependencies = [ | ||
"mypy>=1.0.0", | ||
] | ||
[tool.hatch.envs.types.scripts] | ||
check = "mypy --install-types --non-interactive {args:src/fymail tests}" | ||
|
||
[tool.hatch.build.targets.sdist] | ||
exclude = [ | ||
"/.github", | ||
"/docs", | ||
] | ||
|
||
[tool.hatch.build.targets.wheel] | ||
packages = ["src/fymail"] | ||
|
||
[tool.coverage.run] | ||
source_pkgs = ["fymail"] | ||
branch = true | ||
parallel = true | ||
omit = [ | ||
"src/fymail/__about__.py", | ||
] | ||
|
||
[tool.coverage.paths] | ||
fymail = ["src/fymail", "*/fymail/src/fymail"] | ||
tests = ["tests", "*/fymail/tests"] | ||
|
||
[tool.coverage.report] | ||
exclude_lines = [ | ||
"no cov", | ||
"if __name__ == .__main__.:", | ||
"if TYPE_CHECKING:", | ||
] |
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 @@ | ||
from .fymail import FyMail | ||
|
||
__version__ = "0.0.1dev" |
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,49 @@ | ||
class FyMailError(Exception): | ||
def __init__(self, message): | ||
self.message = message | ||
super().__init__(self.message) | ||
|
||
def __str__(self): | ||
return f"FyMailError::{self.__class__.__name__}: {self.message}" | ||
|
||
|
||
class NoProviderNameError(FyMailError): | ||
message = "Provider name is required" | ||
|
||
def __init__(self): | ||
super().__init__(self.message) | ||
|
||
|
||
class NoProviderPackageError(FyMailError): | ||
message = "Provider package path is required" | ||
|
||
def __init__(self): | ||
super().__init__(self.message) | ||
|
||
|
||
class NoRuleNameError(FyMailError): | ||
message = "Rule name is required" | ||
|
||
def __init__(self): | ||
super().__init__(self.message) | ||
|
||
|
||
class NoRuleUrlPathError(FyMailError): | ||
message = "Rule Path is required" | ||
|
||
def __init__(self): | ||
super().__init__(self.message) | ||
|
||
|
||
class NoProviderBaseUrlPathError(FyMailError): | ||
message = "Provider base path is required" | ||
|
||
def __init__(self): | ||
super().__init__(self.message) | ||
|
||
|
||
class ProvideNotExistsError(FyMailError): | ||
def __init__(self, *, provider_name): | ||
self.message = f"Provider {provider_name} not exists" | ||
super().__init__(self.message) | ||
|
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,32 @@ | ||
import asyncio | ||
import aiohttp | ||
from functools import cached_property, cache | ||
|
||
from fymail.provider_manager import ProviderManger | ||
from fymail.providers.base.provider_base import ProviderBase | ||
from functools import cache, cached_property | ||
|
||
|
||
class FyMail: | ||
|
||
def __init__(self): | ||
self.pm = ProviderManger() | ||
self.pm.register_plugin() | ||
|
||
async def get(self, | ||
*, | ||
iden: str, | ||
provider: str, | ||
auth: str) -> str: | ||
provider = self.pm.get_provider(provider) | ||
async with aiohttp.ClientSession() as session: | ||
return await provider.get(session, auth, iden) | ||
|
||
async def get_bulk(self, | ||
path: str, | ||
provider: str, | ||
io_type: str = None, | ||
delimiter: str = None, | ||
col: int = None, | ||
) -> str: | ||
raise NotImplementedError |
Oops, something went wrong.