forked from katsangati/fundingwiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
55 lines (48 loc) · 2.34 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
This is a top-level script for managing the tables and pages on Innovations in Fundraising Wiki.
It provides command-line access to the possible operations on the wiki content using the Airtable
database.
The settings for accessing the Wiki need to be specified in the config.json file.
"""
import wikimanager
import argparse
def main(wiki_version, table_name, mode, resource_type):
"""Create or update wiki content.
Args:
wiki_version: which wiki we are trying to modify - local test or public official one
table_name: which table on Airtable we are trying to use
mode: do we want to create specified content or update existing content based on changed records
resource_type: type of content we want to create or update - wiki table, wiki pages or both
"""
manager = wikimanager.WikiManager(wiki_version)
manager.setup_table(table_name)
if mode == 'create':
if resource_type == 'table':
manager.create_table()
elif resource_type == 'pages':
manager.create_pages()
elif resource_type == 'both':
manager.create_table_pages()
else:
print("Resource type unrecognized. Please choose from 'table', 'pages' or 'both'.")
elif mode == 'update':
if resource_type == 'table':
manager.update_table()
elif resource_type == 'pages':
manager.update_pages()
elif resource_type == 'both':
manager.update_table_pages()
else:
print("Resource type unrecognized. Please choose from 'table', 'pages' or 'both'.")
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("wiki_version", type=str, help="Specify the DW version",
choices=["official", "test"])
parser.add_argument("table_name", type=str, help="Specify which table you want to use")
parser.add_argument("mode", type=str,
help="Specify whether you want to create a new resource or update an existing one",
choices=["create", "update"])
parser.add_argument("resource_type", type=str, help="Specify if your resource is a table or a set of pages",
choices=["table", "pages", "both"])
args = parser.parse_args()
main(args.wiki_version, args.table_name, args.mode, args.resource_type)