-
Notifications
You must be signed in to change notification settings - Fork 1
/
feed.py
132 lines (107 loc) · 4.59 KB
/
feed.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#
# Copyright (C) Codeplay Software Limited.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use these files except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# For your convenience, a copy of the License has been included in this
# repository.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import logging
import time
from argparse import ArgumentParser
from markdownfeeds.Gatherer import Gatherer
from src.feeds.AcademyLessonFeed import AcademyLessonFeed
from src.feeds.EventFeed import EventFeed
from src.feeds.ImplementationActivityFeed import ImplementationActivityFeed
from src.feeds.NewsFeed import NewsFeed
from src.feeds.PlaygroundSampleFeed import PlaygroundSampleFeed
from src.feeds.ProjectFeed import ProjectFeed
from src.feeds.ResearchPaperFeed import ResearchPaperFeed
from src.feeds.VideoFeed import VideoFeed
from src.feeds.contributors.ContributorFeed import ContributorFeed
def load_command_line_args():
"""
Load the relevant command line arguments
:return:
"""
argument_parser = ArgumentParser()
argument_parser.add_argument('-s',
'--siteUrl',
dest='site_url',
help='The site URL.',
required=True)
argument_parser.add_argument('-a',
'--assetUrl',
dest='asset_base_url',
help='The static asset base URL.',
required=True)
argument_parser.add_argument('-b',
'--feedBaseUrl',
dest='feed_base_url',
help='The base feed URL.',
required=True)
argument_parser.add_argument('-g',
'--githubApiKey',
dest='github_api_key',
help='A GitHub API key, used to pull information from API.',
required=True)
argument_parser.add_argument('-i',
'--itemsPerFeedPage',
dest='items_per_feed_page',
help='Maximum items per feed page.',
default=100,
required=False)
argument_parser.add_argument('-d',
'--debug',
dest='debug_mode',
help='Enable debug mode, will cause stack trace to print.',
required=False,
default=False,
action='store_true')
return argument_parser.parse_args()
if __name__ == '__main__':
debug = False
try:
# Parse arguments
args = load_command_line_args()
debug = args.debug_mode
logging.basicConfig(level=logging.INFO if debug else logging.WARNING)
# Start time
start_time = round(time.time() * 1000)
# Vars
print('Generating feeds....')
# Set some require attributes
ImplementationActivityFeed.GITHUB_API_KEY = args.github_api_key
ProjectFeed.GITHUB_API_KEY = args.github_api_key
# Files to skip when looking for feed markdown files
skip_files = ['README.md']
contributions = ContributorFeed(args, 'contributors').run_standalone()
Gatherer([
EventFeed(args, 'events'),
NewsFeed(args, 'news'),
PlaygroundSampleFeed(args, 'playground_samples'),
ResearchPaperFeed(args, 'research_papers'),
VideoFeed(args, 'videos'),
AcademyLessonFeed(args),
ImplementationActivityFeed(args),
ProjectFeed(args, 'projects')
]).generate()
# Print success and time took
time_diff_in_seconds = (round(time.time() * 1000) - start_time) / 1000
print(f'Success, took {time_diff_in_seconds}s.')
exit(0)
except Exception as e:
if debug:
raise e
print('Error: ' + str(e.__str__().encode('ascii', errors='ignore').decode('ascii')))
exit(1)