-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
62 lines (50 loc) · 1.85 KB
/
example.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
"""
This file supposed to be a documented template for parsers.
You can use this file under WTFPL (http://www.wtfpl.net/txt/copying/)
"""
from typing import Optional, List
from upt.serviceparser import (
ServiceParser,
BadTaskError,
BeautifulSoup,
)
#from upt.sampler import chunkify
# Inheritance from BaseParser is required
# ServiceParser provides more features by default, like login
class ExampleParser(ServiceParser):
@property
def description(self) -> str:
# return description of your parser
return 'Example (https://example.com/)'
@property
def aliases(self):
# return list of aliases for your parser, it must be non-empty
return ['example', 'ex']
@property
def login_page(self) -> Optional[str]:
# return login page if your parser may need logins
#return 'https://example.com/login/'
# return None to disable login feature
return None
# next 2 functions has task argument
# task is a tuple of arguments (string) passed to parser
def url_finder(self, task) -> str:
# return task URL based on given task
#return f'http://example.com/problemset/{task[0]}'
# raise BadTaskError if you can't detect task
raise BadTaskError()
def placer(self, task) -> str:
# return path to the given task
# this path should be relative to root (configs)
#return f'example/{task[0]}'
# raise BadTaskError if you can't detect task
raise BadTaskError()
def sampler(self, soup: BeautifulSoup) -> List[List[str]]:
# return samples from given soup
# this function returns a list in this format
# [[input_0, output_0], [input_1, output_1], ...]
# you may use chunkify here as a utility function
return []
# register parsers
def register():
return [ExampleParser]