Commit b9253f6c authored by David Gene's avatar David Gene
Browse files

Merge branch 'master' of gitlab.com:astrosticks/scratchybot

parents 1be935ab 6988c55a
......@@ -32,8 +32,7 @@ _render_params = {
}
_jinja_env = Environment(
loader=FileSystemLoader(TEMPLATES_PATH),
autoescape=select_autoescape(['jinja','html'])
loader=FileSystemLoader(TEMPLATES_PATH)
)
# _jinja_env.filters['px'] = lambda x: '{}px'.format(x)
_jinja_env.filters['pxRender'] = lambda x: '{}px'.format(int(x)*(_render_params['container']['width']/_render_params['render']['width']))
......
{
"project_comment": {
"id":179134061,"parent_id":null,"commentee_id":null,"content":"This is a test comment that I&apos;m leaving to include some fancy characters $^*()[]&lt;&gt;&amp;% <img src=\"/images/emoji/meow.png\" class=\"emoji\" alt=\"meow emoji\"> <img src=\"/images/emoji/gobo.png\" class=\"emoji\" alt=\"gobo emoji\"> <img src=\"/images/emoji/waffle.png\" class=\"emoji\" alt=\"waffle emoji\"> <img src=\"/images/emoji/pizza-cat.png\" class=\"emoji\" alt=\"pizza-cat emoji\"> <img src=\"/images/emoji/cool-cat.png\" class=\"emoji\" alt=\"cool-cat emoji\"> and a link to my most recent project https://scratch.mit.edu/projects/418309015/ as well as a mention of another user @Astro947 ","datetime_created":"2021-01-06T21:59:54.000Z","datetime_modified":"2021-01-06T21:59:54.000Z","visibility":"visible","author":{"id":578765,"username":"Astro947RMXs","scratchteam":false,"image":"https://cdn2.scratch.mit.edu/get_image/user/578765_60x60.png"},"reply_count":0
},
"project_thumbnail": {
}
}
\ No newline at end of file
......@@ -13,12 +13,6 @@ import ScratchNativeRender
MENTION_RE = '(?<=\\W)@\\w+' # matches cases like `@username`
LINK_RE = '((\\w+:\\/\\/\\S+)|(\\w+[\\.:]\\w+\\S+))[^\\s,\\.]' # matches cases like www.google.com
FORMATS = [
'text',
'image'
]
DEFAULT_FORMAT = 'text'
POST_TYPES = [
'project_comment',
'project_thumbnail',
......@@ -37,6 +31,8 @@ FRONT_PAGE_CATEGORIES = {
DEFAULT_FRONT_PAGE_COMMENTS_SOURCE = 'top_loved'
DEFAULT_FRONT_PAGE_THUMBNAIL_SOURCE = 'newest'
EXAMPLE_SOURCE = []
config = json.loads(open('./config.json','r').read())
def getJsonFromUrl(url:str):
......@@ -150,10 +146,12 @@ def get_project_author(project_id):
def fetch_comments_as_posts():
"""Return a list of all comments under a project that satisfy the rules enabled in config.json"""
project_id = random_project_id()
author = get_project_author(project_id)
comments = getJsonFromUrl('https://api.scratch.mit.edu/users/{}/projects/{}/comments?offset=0&limit=40'.format(author, project_id))
if len(EXAMPLE_SOURCE) > 0:
comments = EXAMPLE_SOURCE
else:
project_id = random_project_id()
author = get_project_author(project_id)
comments = getJsonFromUrl('https://api.scratch.mit.edu/users/{}/projects/{}/comments?offset=0&limit=40'.format(author, project_id))
comment_valid_args = {
'min_words': config['minWords'],
......@@ -255,14 +253,20 @@ def handleArgs():
default="top_loved",
)
parser.add_argument(
'-f', '--format',
help='Format of post to make',
choices=FORMATS,
default='text',
'-e', '--example',
help='Use preloaded data, for testing',
action='store_const',
const=True,
default=False,
)
args = parser.parse_args()
# Temporary way to expand scope of args, will move argument handling to higher level at some point
if args.example:
with open('example_sources.json') as ef:
EXAMPLE_SOURCE.append(json.load(ef)[args.type])
# Assert over arguments
try:
assert args.number > 0
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment