Skip to content

Commit 957da82

Browse files
committed
Add github action
1 parent cc3c491 commit 957da82

File tree

9 files changed

+135
-36
lines changed

9 files changed

+135
-36
lines changed

.github/workflows/test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Coverage Test
2+
on:
3+
- push
4+
- pull_request
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- name: Install dependencies
11+
run: |
12+
python -m pip install --upgrade pip
13+
python -m pip install wheel
14+
pip install -r requirements.txt
15+
- name: Test with pytest
16+
run: |
17+
coverage run --omit="*/test*" -m unittest -v
18+
- uses: codecov/codecov-action@v3

.travis.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

README.ko.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
# comcigan-py
2-
[![Travis (.com)](https://img.shields.io/travis/com/Team-IF/comcigan-py?logo=travis&style=flat-square)](https://www.travis-ci.com/github/Team-IF/comcigan-py) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/comcigan?logo=python&style=flat-square)](https://pypi.org/project/comcigan/) [![PyPI](https://img.shields.io/pypi/v/comcigan?logo=python&style=flat-square)](https://pypi.org/project/comcigan/) [![PyPI - Downloads](https://img.shields.io/pypi/dm/comcigan?style=flat-square)](https://pypi.org/project/comcigan/) [![Codecov](https://img.shields.io/codecov/c/github/Team-IF/comcigan-py?logo=codecov&style=flat-square)](https://app.codecov.io/gh/Team-IF/comcigan-py)
32

4-
[English](./README.md) | [**한국어**](./README.ko.md)
3+
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/comcigan?logo=python&style=flat-square)](https://pypi.org/project/comcigan/) [![PyPI](https://img.shields.io/pypi/v/comcigan?logo=python&style=flat-square)](https://pypi.org/project/comcigan/) [![PyPI - Downloads](https://img.shields.io/pypi/dm/comcigan?style=flat-square)](https://pypi.org/project/comcigan/) [![Codecov](https://img.shields.io/codecov/c/github/Team-IF/comcigan-py?logo=codecov&style=flat-square)](https://app.codecov.io/gh/Team-IF/comcigan-py)
4+
5+
[English](./README.md) | [**한국어**](./README.ko.md)
56

67
comcigan-py는 파이썬으로 제작된 ["컴시간 학생시간표"](http://컴시간학생.kr)의 파서 입니다.
8+
79
## 설치
10+
811
[pip](https://pip.pypa.io/en/stable/quickstart/) 를 통해 다음과 같이 입력해서 라이브러리를 설치/업데이트 합니다 :
12+
913
```sh
1014
$ pip install comcigan
1115
```
16+
1217
## 예제
18+
1319
동기/비동기 버전에 대한 간단한 예제
20+
1421
```python
1522
from comcigan import School, AsyncSchool
1623

@@ -30,5 +37,6 @@ print(myschool[2][3][3][3])
3037
```
3138

3239
## 라이선스
40+
3341
이 프로젝트는 GNU Lesser General Public License version 3.0 or later (LGPL v3.0+)의 라이선스를 따릅니다.
3442
자세한 사항은 위 라이선스를 참조해주시길 바랍니다.

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
# comcigan-py
2-
[![Travis (.com)](https://img.shields.io/travis/com/Team-IF/comcigan-py?logo=travis&style=flat-square)](https://www.travis-ci.com/github/Team-IF/comcigan-py) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/comcigan?logo=python&style=flat-square)](https://pypi.org/project/comcigan/) [![PyPI](https://img.shields.io/pypi/v/comcigan?logo=python&style=flat-square)](https://pypi.org/project/comcigan/) [![PyPI - Downloads](https://img.shields.io/pypi/dm/comcigan?style=flat-square)](https://pypi.org/project/comcigan/) [![Codecov](https://img.shields.io/codecov/c/github/Team-IF/comcigan-py?logo=codecov&style=flat-square)](https://app.codecov.io/gh/Team-IF/comcigan-py)
32

4-
[**English**](./README.md) | [한국어](./README.ko.md)
5-
3+
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/comcigan?logo=python&style=flat-square)](https://pypi.org/project/comcigan/) [![PyPI](https://img.shields.io/pypi/v/comcigan?logo=python&style=flat-square)](https://pypi.org/project/comcigan/) [![PyPI - Downloads](https://img.shields.io/pypi/dm/comcigan?style=flat-square)](https://pypi.org/project/comcigan/) [![Codecov](https://img.shields.io/codecov/c/github/Team-IF/comcigan-py?logo=codecov&style=flat-square)](https://app.codecov.io/gh/Team-IF/comcigan-py)
4+
5+
[**English**](./README.md) | [한국어](./README.ko.md)
6+
67
Comcigan-py is a parser for korean school timetable service ["comcigan"](http://컴시간학생.kr) made with python.
8+
79
## Installation
10+
811
Install and update using [pip](https://pip.pypa.io/en/stable/quickstart/):
12+
913
```sh
1014
$ pip install comcigan
1115
```
16+
1217
## Example
18+
1319
A simple example for sync/async version
20+
1421
```python
1522
from comcigan import School, AsyncSchool
1623

@@ -30,4 +37,5 @@ print(myschool[2][3][3][3])
3037
```
3138

3239
## License
40+
3341
This project is under the GNU Lesser General Public License version 3.0 or later (LGPL v3.0+).

comcigan/school.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
from typing import List, Tuple
2-
31
from base64 import b64encode
42
from json import loads
3+
from typing import List, Tuple
54

6-
from requests import get
75
from bs4 import BeautifulSoup
6+
from requests import get
87

98
from .reg import (
10-
routereg,
11-
prefixreg,
12-
orgdatareg,
139
daydatareg,
14-
thnamereg,
15-
sbnamereg,
16-
regsearch,
1710
extractint,
11+
orgdatareg,
12+
prefixreg,
13+
regsearch,
14+
routereg,
15+
sbnamereg,
16+
thnamereg,
1817
)
1918

2019

@@ -55,7 +54,12 @@ class School:
5554
def __init__(self, name: str):
5655
sc_search = get(
5756
SEARCHURL
58-
+ "%".join(str(name.encode("EUC-KR")).upper()[2:-1].replace("\\X", "\\").split("\\"))
57+
+ "%".join(
58+
str(name.encode("EUC-KR"))
59+
.upper()[2:-1]
60+
.replace("\\X", "\\")
61+
.split("\\")
62+
)
5963
)
6064
sc_search.encoding = "UTF-8"
6165
sc_list = loads(sc_search.text.replace("\0", ""))["학교검색"]
@@ -93,7 +97,9 @@ def refresh(self):
9397
(
9498
subjects[int(str(x)[-2:])],
9599
long_subjects[int(str(x)[-2:])],
96-
"" if int(str(x)[:-2]) >= len(teachers) else teachers[int(str(x)[:-2])],
100+
""
101+
if int(str(x)[:-2]) >= len(teachers)
102+
else teachers[int(str(x)[:-2])],
97103
)
98104
for x in filter(lambda x: str(x)[:-2], trim(oneday[1:]))
99105
]

comcigan/school_new.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import re
2+
from base64 import b64encode
3+
from json import loads
4+
from typing import cast
5+
from urllib.parse import quote
6+
7+
from bs4 import BeautifulSoup
8+
from bs4.element import Tag
9+
from requests import Response, get
10+
11+
BASEURL = "http://comci.net:4082"
12+
SCSEARCH_REGEX = re.compile(r"(?<=url:['\"]\.).*?(?=['\"])")
13+
TIMEGET_REGEX = re.compile(r"(?<=var sc3=['\"]\.).*?(?=['\"])")
14+
PREFIX_REGEX = re.compile(r"(?<=sc_data\(['\"]).*?(?=['\"])")
15+
THNAME_REGEX = re.compile(r"(?<=자료\.)자료\d*?(?=\.length)")
16+
17+
while True:
18+
comci_resp: Response = get(f"{BASEURL}/st", timeout=60)
19+
comci_resp.encoding = "EUC-KR"
20+
comci = comci_resp.text.replace("\0", "")
21+
if "refresh" in comci:
22+
continue
23+
break
24+
25+
script = cast(
26+
Tag,
27+
BeautifulSoup(comci, "lxml").find_all(
28+
"script", attrs={"language": "JavaScript", "type": "text/JavaScript"}
29+
)[0],
30+
).text
31+
SEARCHPATH = SCSEARCH_REGEX.findall(script)[0]
32+
TIMEPATH = TIMEGET_REGEX.findall(script)[0]
33+
PREFIX = PREFIX_REGEX.findall(script)[0]
34+
THNAME = THNAME_REGEX.findall(script)[0]
35+
36+
37+
class School:
38+
name: str
39+
school_code: int
40+
_timeurl: str
41+
42+
def __init__(self, name: str, region: str | None = None):
43+
sc_search = get(
44+
BASEURL + SEARCHPATH + quote(name, encoding="EUC-KR"), timeout=60
45+
)
46+
sc_search.encoding = "UTF-8"
47+
sc_list = loads(sc_search.text.replace("\0", ""))["학교검색"]
48+
sc_list = sc_list if not region else [x for x in sc_list if x[1] == region]
49+
if len(sc_list) > 1:
50+
raise ValueError(
51+
"More than one school is searched by the query passed.",
52+
)
53+
if len(sc_list) == 0:
54+
raise NameError("No schools have been searched by the query passed.")
55+
56+
self.region = sc_list[0][1]
57+
self.name = sc_list[0][2]
58+
self.sccode = sc_list[0][3]
59+
self._timeurl = (
60+
f"{BASEURL}{TIMEPATH}"
61+
+ b64encode(f"{PREFIX}{str(self.sccode)}_0_1".encode()).decode()
62+
)
63+
print(self._timeurl)
64+
print(THNAME)
65+
self.refresh()
66+
67+
def refresh(self):
68+
time_res = get(self._timeurl, timeout=60)
69+
time_res.encoding = "UTF-8"
70+
rawtimetable = loads(time_res.text.replace("\0", ""))
71+
print(rawtimetable[THNAME])
72+
73+
74+
if __name__ == "__main__":
75+
School("컴시간")

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ aiohttp
22
requests
33
beautifulsoup4
44
coverage
5+
lxml

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from os import environ
2-
from setuptools import setup, find_packages
2+
3+
from setuptools import find_packages, setup
34

45
version = (
56
environ["TRAVIS_TAG"].lstrip("v")
@@ -17,7 +18,7 @@
1718
long_description_content_type="text/markdown",
1819
url="https://github.com/Coder-Iro/comcigan-py",
1920
packages=find_packages(),
20-
install_requires=["requests", "beautifulsoup4", "aiohttp"],
21+
install_requires=["requests", "beautifulsoup4", "aiohttp", "lxml"],
2122
python_requires=">=3.7",
2223
classifiers=[
2324
# 패키지에 대한 태그

0 commit comments

Comments
 (0)