kattis-cli 0.1.15__py3-none-any.whl → 0.1.16__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
kattis_cli/download.py CHANGED
@@ -34,6 +34,19 @@ def create_problem_folder(problemid: str) -> Path:
34
34
  return root_problem_folder
35
35
 
36
36
 
37
+ def download_html(problemid: str) -> str:
38
+ """Get html content from Kattis problem page.
39
+
40
+ Args:
41
+ problemid (str): problemid
42
+ """
43
+ response = requests.get(settings.KATTIS_PROBLEM_URL + problemid, timeout=5)
44
+ if response.status_code == 200:
45
+ return response.text.strip()
46
+ else:
47
+ raise requests.exceptions.InvalidURL(f"Error: {response.status_code}")
48
+
49
+
37
50
  def load_problem_metadata(problemid: str = '') -> Dict[Any, Any]:
38
51
  """Load problem metadata from problem folder.
39
52
 
@@ -73,43 +86,31 @@ def load_problem_metadata(problemid: str = '') -> Dict[Any, Any]:
73
86
  metadata['accepted'] = 0
74
87
  config.update_problem_metadata(problemid, metadata)
75
88
  else:
76
- metadata = _download_metadata(root_problem_folder, problemid)
89
+ html = download_html(problemid)
90
+ metadata = _parse_metadata(problemid, html)
91
+ save_metadata(problemid, metadata)
77
92
  return metadata
78
93
 
79
94
 
80
- def make_soup(problemid: str) -> BeautifulSoup:
81
- """Scrape kattis page given problemid and return a BeautifulSoup object.
82
-
83
- Args:
84
- problemid (str): problemid
85
-
86
- Returns:
87
- BeautifulSoup: BeautifulSoup object of the problem page.
88
- """
89
- response = requests.get(settings.KATTIS_PROBLEM_URL + problemid, timeout=5)
90
- if response.status_code == 200:
91
- return BeautifulSoup(response.text.strip(), "html.parser")
92
- else:
93
- raise requests.exceptions.InvalidURL(f"Error: {response.status_code}")
94
-
95
-
96
- def _download_metadata(root_problem_folder: Path,
97
- problemid: str) -> Dict[str, Any]:
98
- """Download problem metadata from Kattis and save them to problem folder.
99
- This function should only be called if the metadata file does not exist.
95
+ def _parse_metadata(problemid: str,
96
+ html: str,
97
+ ) -> Dict[str, Any]:
98
+ """Parse metadata from Kattis problm page.
99
+ This function should only be called if
100
+ the metadata file does not exist.
100
101
 
101
102
  Args:
103
+ root_problem_folder (Path): problem folder
102
104
  problemid (str): Kattis problemid
103
105
 
104
106
  Returns:
105
107
  Dict: problem metadata
106
108
  """
107
109
 
108
- soup = make_soup(problemid)
109
-
110
+ soup = BeautifulSoup(html, "html.parser")
110
111
  meta_data = {'problemid': problemid, 'title': '',
111
112
  'cpu_limit': 'None', 'mem_limit': 'None',
112
- 'difficulty': 'None', 'source': 'None',
113
+ 'difficulty': 'None',
113
114
  'submissions': 0, 'accepted': 0}
114
115
 
115
116
  # get the title of the problem
@@ -118,26 +119,41 @@ def _download_metadata(root_problem_folder: Path,
118
119
  meta_data["title"] = title.text
119
120
 
120
121
  # get the cpu time limit, memory limit, difficulty, and source
121
- data = soup.find_all("div", {"class": "metadata_list-item"})
122
- name_mapping = {'cpu_limit': 'cpu_limit',
123
- 'mem_limit': 'mem_limit',
124
- 'difficulty': 'difficulty',
125
- 'source': 'source',
122
+ data = soup.find("div", {"class": "metadata-grid"})
123
+ name_mapping = {'metadata-cpu-card': 'cpu_limit',
124
+ 'metadata-memmory-card': 'mem_limit',
125
+ 'metadata-difficulty-card': 'difficulty',
126
126
  }
127
- for item in data:
127
+
128
+ for key, key1 in name_mapping.items():
128
129
  try:
129
- data_name = item.attrs['data-name'].split('-')[1]
130
- if data_name in name_mapping:
131
- children = item.findChildren('span')
132
- meta_data[name_mapping[data_name]] = children[-1].text.strip()
133
- except BaseException:
130
+ value = ''
131
+ div = data.findChild('div', {'class': key}) # type: ignore
132
+ if key == 'metadata-difficulty-card':
133
+ span = div.findChild( # type: ignore
134
+ 'span', {
135
+ 'class': 'difficulty_number'})
136
+ value += span.text.strip() + ' ' # type: ignore
137
+ span = div.findChild('span', # type: ignore
138
+ {'class': 'text-blue-200'})
139
+ value += span.text.strip() # type: ignore
140
+ meta_data[key1] = value
141
+ except AttributeError:
134
142
  pass
143
+ return meta_data
144
+
135
145
 
136
- # save metadata to file
146
+ def save_metadata(problemid: str, metadata: Dict[str, Any]) -> None:
147
+ """Save metadata to problem folder.
148
+
149
+ Args:
150
+ problemid (str): problemid
151
+ metadata (Dict[str, Any]): metadata
152
+ """
153
+ root_problem_folder = create_problem_folder(problemid)
137
154
  metadata_file = root_problem_folder.joinpath(f"{problemid}.yaml")
138
155
  with open(metadata_file, "w", encoding='utf-8') as f:
139
- yaml.dump(meta_data, f, default_flow_style=False, allow_unicode=True)
140
- return meta_data
156
+ yaml.dump(metadata, f, default_flow_style=False, allow_unicode=True)
141
157
 
142
158
 
143
159
  def download_sample_data(problemid: str) -> None:
kattis_cli/ui.py CHANGED
@@ -53,26 +53,18 @@ def show_problem_metadata(problemid: str = '') -> Dict[Any, Any]:
53
53
  justify="center",
54
54
  style="cyan",
55
55
  no_wrap=False)
56
- table.add_column(
57
- "Source",
58
- justify="center",
59
- style="cyan",
60
- no_wrap=False)
61
- # [link=https://www.willmcgugan.com]blog[/link]
56
+
62
57
  p_id = metadata['problemid']
63
58
  problem_link = f"[link={settings.KATTIS_PROBLEM_URL}{p_id}]"
64
59
  problem_link += f"{p_id}[/link]"
65
- source = metadata['source']
66
- sources_link = f"[link={settings.KATTIS_SOURCE_URL}{source}]"
67
- sources_link += f"{source}[/link]"
68
60
  # console.print(sources_link)
69
61
  table.add_row(problem_link,
70
62
  metadata['difficulty'],
71
63
  metadata['cpu_limit'],
72
64
  metadata['mem_limit'],
73
65
  str(metadata['submissions']),
74
- str(metadata['accepted']),
75
- sources_link)
66
+ str(metadata['accepted'])
67
+ )
76
68
 
77
69
  console.print(table)
78
70
  elif problemid:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kattis-cli
3
- Version: 0.1.15
3
+ Version: 0.1.16
4
4
  Summary: A command-line tool for Kattis
5
5
  Home-page: https://github.com/rambasnet/kattis-cli
6
6
  Author: Ram Basnet
@@ -38,6 +38,7 @@ Based on Official Kattis CLI: [https://github.com/Kattis/kattis-cli](https://git
38
38
 
39
39
  - Use Command Line or PowerShell
40
40
  - Make sure python is in your PATH
41
+ - Install Python from Windows Store
41
42
  - if you get codec error while running kattis-cli, run the following command in Command Prompt:
42
43
 
43
44
  ```bash
@@ -71,6 +72,9 @@ pip install kattis-cli
71
72
  python -m pip install kattis-cli
72
73
  ```
73
74
 
75
+ - on Windows add the path shown in the output of the above command to your PATH environment variable
76
+
77
+
74
78
  ## Update Kattis-CLI
75
79
 
76
80
  - remove or rename **.kattis-cli.toml** file in your home directory
@@ -1,18 +1,18 @@
1
1
  kattis_cli/.kattis-cli.toml,sha256=kGh0gmpFAnivyUC9hR8Y1ZqYJeTBWNyBQ9zOg4AInZ0,898
2
2
  kattis_cli/__init__.py,sha256=afN92pog2fGyicY6KNBofYbCBYbYj4Fpi_INUSpsc-E,402
3
- kattis_cli/download.py,sha256=PNOSJmvXaAAwXGtMGb6d2DPq4YCfkWn5BMYa9qzbGtc,5367
3
+ kattis_cli/download.py,sha256=aa0hBg_6Ou8SGrufgkNUjfWEHdmiu7U-W4d-yWHZNOA,5877
4
4
  kattis_cli/kattis.py,sha256=H8Nn1oofjJYAFQ9snpnU4ibKyJUSrsuDGePBx0Gzuvk,13745
5
5
  kattis_cli/kattis_setup.py,sha256=87Ha0MTFbQKwz4SlPCE50FR1tvwtvDtKfboCJEmCDeM,3449
6
6
  kattis_cli/main.py,sha256=PpizTV_9JDr-vgplpuwlgjJrxT62dMVLEC0zPm2R9Zo,3952
7
7
  kattis_cli/settings.py,sha256=d5q4dYj9VqDSqPalleh2oZWtND-1bPB0T2IwdajFrBg,591
8
8
  kattis_cli/test_solution.py,sha256=zzSIM4uKOq5M3igGbr3ELyvrWBr9Uh8lS-t8F4wWLo4,5665
9
- kattis_cli/ui.py,sha256=Q8VjAbQUmrGgtD9aj9wQafv2W1W9oRXThDB5aSiHMuk,3030
9
+ kattis_cli/ui.py,sha256=dI06yncjm8sdLQkupPxGRODvQ6Gbawwuqn-67FrWg6I,2682
10
10
  kattis_cli/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  kattis_cli/utils/config.py,sha256=cr5ssEVWolDbqP8krts0YSK5vSLatKTveeHBRNsLRC8,2277
12
12
  kattis_cli/utils/run_program.py,sha256=NWQ6vtTeWgkaW75r91FIHGXR5cAbeu8yMb5hwzpYFsg,2613
13
13
  kattis_cli/utils/utility.py,sha256=uVgfameMWW4Tp78p8ihaUxnAfjnyA024-Nqkgsp_FSY,11458
14
- kattis_cli-0.1.15.dist-info/LICENSE,sha256=JmBa4SEKBCDWEgiOZcISU4tUCpli6xSpVlSYgkBXSNQ,1067
15
- kattis_cli-0.1.15.dist-info/METADATA,sha256=umkW3NeUmPKiJqNtHbKZrVr5bhjMVd6IxvnB3H7lLxk,5161
16
- kattis_cli-0.1.15.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
17
- kattis_cli-0.1.15.dist-info/entry_points.txt,sha256=kyzGN20VqUPR_H0J_jJUKT-10-cAMFLVegQ6C7tbHss,47
18
- kattis_cli-0.1.15.dist-info/RECORD,,
14
+ kattis_cli-0.1.16.dist-info/LICENSE,sha256=JmBa4SEKBCDWEgiOZcISU4tUCpli6xSpVlSYgkBXSNQ,1067
15
+ kattis_cli-0.1.16.dist-info/METADATA,sha256=gorC4bRZVfDdUBWYCDHAgRjIUaJGmdqfFbfjEBPZy4Q,5304
16
+ kattis_cli-0.1.16.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
17
+ kattis_cli-0.1.16.dist-info/entry_points.txt,sha256=kyzGN20VqUPR_H0J_jJUKT-10-cAMFLVegQ6C7tbHss,47
18
+ kattis_cli-0.1.16.dist-info/RECORD,,