Unify 'org' and 'helloasso-backup-file' arguments.
This commit is contained in:
parent
88f00095fe
commit
243e301043
|
@ -25,11 +25,11 @@ The goal is to sync an HelloAsso event (they call it `forms`) to a Discourse Bad
|
|||
|
||||
First let's discover which HelloAsso 'forms' we can use:
|
||||
|
||||
$ helloasso-to-discourse list-forms ./afpy
|
||||
$ helloasso-to-discourse list-forms afpy
|
||||
|
||||
Then let's discover which Discourse badges we can use:
|
||||
|
||||
$ helloasso-to-discourse list-badges https://discuss.afpy.org "$(pass discuss.afpy.org-api-key)"
|
||||
$ helloasso-to-discourse list-badges https://discuss.afpy.org "$(pass afpy/discuss.afpy.org-api-key)"
|
||||
|
||||
|
||||
### 3 — Sync
|
||||
|
@ -38,8 +38,8 @@ This step actually assigns badges to Discourse users:
|
|||
|
||||
As an example to assign badge "membre" to HelloAsso users having paid for the form named `adhesion-2023-a-l-afpy`:
|
||||
|
||||
$ helloasso-to-discourse sync https://discuss.afpy.org "$(pass discuss.afpy.org-api-key)" ./afpy adhesion-2023-a-l-afpy membre
|
||||
$ helloasso-to-discourse sync https://discuss.afpy.org "$(pass afpy/discuss.afpy.org-api-key)" afpy adhesion-2024-a-l-afpy membre
|
||||
|
||||
And an exemple to assign Discourse badge `pyconfr-2023` to members having registered for the `pyconfr-2023` event on HelloAsso:
|
||||
|
||||
$ helloasso-to-discourse sync https://discuss.afpy.org "$(pass discuss.afpy.org-api-key)" ./afpy pyconfr-2023 pyconfr-2023
|
||||
$ helloasso-to-discourse sync https://discuss.afpy.org "$(pass afpy/discuss.afpy.org-api-key)" afpy pyconfr-2023 pyconfr-2023
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import argparse
|
||||
import datetime as dt
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
|
@ -29,7 +30,7 @@ def parse_args():
|
|||
)
|
||||
sync_parser.add_argument("discourse_url")
|
||||
sync_parser.add_argument("discourse_api_key")
|
||||
sync_parser.add_argument("helloasso_backup_file")
|
||||
sync_parser.add_argument("org")
|
||||
sync_parser.add_argument(
|
||||
"form_slug",
|
||||
help="See the `list-forms` subcommand to learn which one you can use.",
|
||||
|
@ -41,7 +42,7 @@ def parse_args():
|
|||
"list-forms", help="List HelloAsso forms, to use with `sync`"
|
||||
)
|
||||
list_form_parser.set_defaults(func=main_list_form)
|
||||
list_form_parser.add_argument("helloasso_backup_file")
|
||||
list_form_parser.add_argument("org")
|
||||
|
||||
list_badges_parser = subparsers.add_parser(
|
||||
"list-badges", help="List Discourse badges, to use with `sync`"
|
||||
|
@ -140,9 +141,14 @@ def main():
|
|||
|
||||
|
||||
def main_list_form(args):
|
||||
helloasso_backup = json.loads(
|
||||
Path(args.helloasso_backup_file).read_text(encoding="UTF-8")
|
||||
)
|
||||
mtime = dt.datetime.fromtimestamp(Path(args.org).stat().st_mtime)
|
||||
if dt.datetime.now() - mtime > dt.timedelta(days=100):
|
||||
print("\nBeware, local copy of Helloasso data is outdated, maybe run:")
|
||||
print(
|
||||
""" helloasso-to-discourse fetch "$(pass helloasso-clientid)" """
|
||||
f""""$(pass helloasso-clientsecret)" {args.org}\n"""
|
||||
)
|
||||
helloasso_backup = json.loads(Path(args.org).read_text(encoding="UTF-8"))
|
||||
forms = [
|
||||
(item["order"]["formType"], item["order"]["formSlug"])
|
||||
for item in helloasso_backup
|
||||
|
@ -158,7 +164,7 @@ def main_list_form(args):
|
|||
print()
|
||||
print("Use the `name` for the `sync` command, like:")
|
||||
print(
|
||||
f'helloasso-to-discourse sync https://discuss.afpy.org "$(pass discuss.afpy.org-api-key)" ./afpy form-slug badge-slug'
|
||||
f'helloasso-to-discourse sync https://discuss.afpy.org "$(pass discuss.afpy.org-api-key)" afpy form-slug badge-slug'
|
||||
)
|
||||
|
||||
|
||||
|
@ -185,9 +191,7 @@ def main_list_badges(args):
|
|||
|
||||
|
||||
def main_sync(args):
|
||||
helloasso_backup = json.loads(
|
||||
Path(args.helloasso_backup_file).read_text(encoding="UTF-8")
|
||||
)
|
||||
helloasso_backup = json.loads(Path(args.org).read_text(encoding="UTF-8"))
|
||||
discourse = Discourse(args.discourse_url, args.discourse_api_key)
|
||||
with discourse:
|
||||
from_helloasso = {
|
||||
|
|
Loading…
Reference in New Issue