|
11 | 11 |
|
12 | 12 | if __name__ == "__main__": |
13 | 13 |
|
14 | | - parser = argparse.ArgumentParser() |
15 | | - parser.add_argument("-p", "--post", default="draft.yaml", required=True, |
16 | | - help="YAML file containing the post to publish.", type=str) |
17 | | - parser.add_argument("--publish", help="Publish the draft.", action="store_true") |
18 | | - args = parser.parse_args() |
19 | | - |
20 | | - with open(args.post, "r") as fp: |
21 | | - post_data = yaml.safe_load(fp) |
22 | | - |
23 | | - title = post_data.get("title", "") |
24 | | - subtitle = post_data.get("subtitle", "") |
25 | | - body = post_data.get("body", {}) |
26 | | - |
27 | | - api = Api( |
28 | | - email=os.getenv("EMAIL"), |
29 | | - password=os.getenv("PASSWORD"), |
30 | | - publication_url=os.getenv("PUBLICATION_URL"), |
31 | | - ) |
32 | | - |
33 | | - post = Post(title, subtitle, os.getenv("USER_ID")) |
34 | | - for _, item in body.items(): |
35 | | - post.add(item) |
36 | | - |
37 | | - draft = api.post_draft(post.get_draft()) |
38 | | - |
39 | | - if args.publish: |
40 | | - api.prepublish_draft(draft.get("id")) |
41 | | - |
42 | | - api.publish_draft(draft.get("id")) |
| 14 | + parser = argparse.ArgumentParser() |
| 15 | + parser.add_argument("-p", "--post", default="draft.yaml", required=False, |
| 16 | + help="YAML file containing the post to publish.", type=str) |
| 17 | + parser.add_argument("--publish", help="Publish the draft.", action="store_true", default=False) |
| 18 | + args = parser.parse_args() |
| 19 | + |
| 20 | + with open(args.post, "r") as fp: |
| 21 | + post_data = yaml.safe_load(fp) |
| 22 | + |
| 23 | + title = post_data.get("title", "") |
| 24 | + subtitle = post_data.get("subtitle", "") |
| 25 | + body = post_data.get("body", {}) |
| 26 | + |
| 27 | + api = Api( |
| 28 | + email=os.getenv("EMAIL"), |
| 29 | + password=os.getenv("PASSWORD"), |
| 30 | + publication_url=os.getenv("PUBLICATION_URL"), |
| 31 | + ) |
| 32 | + |
| 33 | + post = Post(title, subtitle, os.getenv("USER_ID")) |
| 34 | + for _, item in body.items(): |
| 35 | + if item.get("type") == "captionedImage": |
| 36 | + image = api.get_image(item.get("src")) |
| 37 | + item.update({"src": image.get("url")}) |
| 38 | + post.add(item) |
| 39 | + |
| 40 | + draft = api.post_draft(post.get_draft()) |
| 41 | + |
| 42 | + if args.publish: |
| 43 | + api.prepublish_draft(draft.get("id")) |
| 44 | + |
| 45 | + api.publish_draft(draft.get("id")) |
0 commit comments