PK!fXXmailgun_cli/__init__.py__version__ = '0.1.6' from .mailgun import Mailgun from .forward import update_from_csvPK!Rtmailgun_cli/cli.pyimport click import pandas as pd from mailgun_cli.forward import update_from_csv from mailgun_cli.mailgun import Mailgun @click.group() def main(): pass @click.command() def routes(): """list all routes""" api = Mailgun() df = pd.DataFrame(api.list_routes()['items']) print(df) @click.command() @click.argument("url") def forward(url): """create 1-to-1 forward mail route using a csv""" update_from_csv(url) main.add_command(routes) main.add_command(forward) if __name__ == '__main__': main() PK!`Inmailgun_cli/forward.pyimport pandas as pd from loguru import logger from tqdm import tqdm from mailgun_cli import Mailgun def clear_existing_routes(mailgun, mark): # STEP 1: delete all existing routes with mark logger.info('Delete Existing routes created by this Cli') for route in tqdm(mailgun.list_routes()['items'], desc='routes to delete'): if route['description'].startswith(mark): id = route['id'] resp = mailgun.delete(id) assert resp.status_code == 200 def update_from_csv(url, mark='[created by mailgun-cli]', proirity=1): """update the route using csv""" logger.info(f'update the route using csv: {url}') forwardlist = pd.read_csv(url) mailgun = Mailgun() clear_existing_routes(mailgun, mark) # STEP 2: create routes for id, row in tqdm(forwardlist.iterrows(), total=forwardlist.shape[0], desc='routes to create'): from_ = row[0].lower() to = row[1].lower() expression = f"match_recipient('{from_}')" action = f"forward('{to}')" description = f"{mark}" resp = mailgun.create_route(expression=expression, action=action, priority=proirity, description=description) assert resp.status_code == 200 if __name__ == '__main__': pass PK![RTmailgun_cli/mailgun.pyimport os from uplink import Consumer, get, Path, Query, params, headers, returns, post, delete class Mailgun(Consumer): """A Python Client for the Mailgun API.""" def __init__(self, apikey=None): if apikey is None: super(Mailgun, self).__init__(base_url="https://api.mailgun.net", auth=('api', os.environ['MAILGUN_API_KEY'])) else: super(Mailgun, self).__init__(base_url="https://api.mailgun.net", auth=('api', apikey)) @returns.json @get("v3/routes") def list_routes(self, limit: Query("limit")=100, skip: Query("skip")=0): """Retrieves the user's public repositories.""" @post("v3/routes") def create_route(self,expression: Query("expression"), action: Query("action"),priority: Query("priority")=0, description: Query( "description")=""): """create a route""" @delete('v3/routes/{id}') def delete(self, id): """delete a route by id""" if __name__ == '__main__': api = Mailgun() resp = api.list_routes(100) import pprint pprint.pprint(resp) PK!H-D*0,mailgun_cli-0.1.6.dist-info/entry_points.txtN+I/N.,()MI/ͳ9z@lqqPK!22#mailgun_cli-0.1.6.dist-info/LICENSEMIT License Copyright (c) 2019 Nutchanon Ninyawee 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.PK!HڽTU!mailgun_cli-0.1.6.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!Hm)`$mailgun_cli-0.1.6.dist-info/METADATATR6S&-B6m'- I&}}}>AGEɌ;|;t'4V(C1/1"d"x<*x_%7u Ψb$*+d \k+:"xJ 5(qe՜%$^F)DRt|1y\`T&1,Yrvn0,b!rO /Kˬ UӴ^YsxE*L!]g{.4n[.y\OKet!*Ձeo<NG1\VV8ekmbvpH>CkMpܥj)`_V}% 8E*j-E -*; z!m^}(zTF6GtMY[ZmZtr|baf99?@El~8<9MǷ'ۋnC*ڈϗv}ς}L U M%O<~f#j|3߸ߤ,Djz;xQ<(aJ\BWH({Y폿'}Vo+9,u3/LޡANUbYD5O6JWjL/oTd}m^57MI97}]Y}dsnHmSaHI] ?f-Ӧ88ksא)zä{B1|>afQ\R״#i]m*zCM l16[K|A?ǡ~Hn]EL_)aB.T.=X(%%=(VLPK!H߷"mailgun_cli-0.1.6.dist-info/RECORD};@| '"*#B<~mp^ibU}]499ӆi9p 3^t6XV~[x7 |dOoeR٩X%-:@S(.zAKq3Q|:zbց(8ikŃWݼ.μ>fP}'PJ̵%ַwܛFڄֺ͕ԗ%|9` ë́IM=yæMPK!fXXmailgun_cli/__init__.pyPK!Rtmailgun_cli/cli.pyPK!`Inmailgun_cli/forward.pyPK![RTmailgun_cli/mailgun.pyPK!H-D*0, mailgun_cli-0.1.6.dist-info/entry_points.txtPK!22#3 mailgun_cli-0.1.6.dist-info/LICENSEPK!HڽTU!mailgun_cli-0.1.6.dist-info/WHEELPK!Hm)`$9mailgun_cli-0.1.6.dist-info/METADATAPK!H߷"mailgun_cli-0.1.6.dist-info/RECORDPK