Skip to content

Commit

Permalink
fix: Use local data file to test TSS.py for PR (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusancky authored Oct 14, 2023
1 parent b40297d commit 1274aa0
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/AllUp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ jobs:
- name: Main
run: python main.py
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_REF: ${{ github.ref }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
SATWIKI_PASSWORD: ${{ secrets.SATWIKI_PASSWORD }}
- name: TSS
run: python TSS.py
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_REF: ${{ github.ref }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
SATWIKI_PASSWORD: ${{ secrets.SATWIKI_PASSWORD }}
Expand Down
57 changes: 36 additions & 21 deletions AllUp_utils/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,45 @@
from os import environ
from pwiki.wiki import Wiki

def pull(title : str):
try:
if environ['GITHUB_REF'] == 'refs/heads/main' and environ['GITHUB_REPOSITORY_OWNER'] == 'yusancky':
def PR_TEST():
return environ['GITHUB_EVENT_NAME'] == 'pull_request'

def MAIN_REPO_BRANCH():
return (environ['GITHUB_REF'] == 'refs/heads/main' and environ['GITHUB_REPOSITORY_OWNER'] == 'yusancky')

def pull(title : str,split_line = False):
if MAIN_REPO_BRANCH():
try:
wiki = Wiki('sat.huijiwiki.com','雨伞CKY',environ['SATWIKI_PASSWORD'])
return (wiki.page_text(title).split('\n') if split_line else wiki.page_text(title))
except:
pass
elif PR_TEST():
match title:
case '模板:天宫空间站任务列表/echarts/data':
return [line.replace('\n','') for line in open('test-sources/TSS-data.wikitext')]
case _:
print('Unable to find test sources.')
try:
wiki = Wiki('sat.huijiwiki.com')
return wiki.page_text(title)
except:
print(f'You do not have permission to get password.\nREF: {environ["GITHUB_REF"]}\nREPO_OWNER: {environ["GITHUB_REPOSITORY_OWNER"]}')
else:
try:
wiki = Wiki('sat.huijiwiki.com')
return wiki.page_text(title)
else:
try:
wiki = Wiki('sat.huijiwiki.com')
return wiki.page_text(title)
except:
print(f'You do not have permission to get password.\nREF: {environ["GITHUB_REF"]}\nREPO_OWNER: {environ["GITHUB_REPOSITORY_OWNER"]}')
except:
pass
except:
print(f'You do not have permission to get password.\nREF: {environ["GITHUB_REF"]}\nREPO_OWNER: {environ["GITHUB_REPOSITORY_OWNER"]}')

def push(title : str,content_id : str,content : str):
print(
f'### {content_id}\n\n```go\n{content}\n```\n\n',
file = open('PR_preview.md','a',encoding = 'utf-8')
)
try:
if environ['GITHUB_REF'] == 'refs/heads/main' and environ['GITHUB_REPOSITORY_OWNER'] == 'yusancky':
if MAIN_REPO_BRANCH():
try:
wiki = Wiki('sat.huijiwiki.com','雨伞CKY',environ['SATWIKI_PASSWORD'])
wiki.edit(title,content,'Edit via AllUp-Satwiki')
else:
print(f'You do not have permission to get password.\nREF: {environ["GITHUB_REF"]}\nREPO_OWNER: {environ["GITHUB_REPOSITORY_OWNER"]}')
except:
pass
except:
pass
elif PR_TEST():
print(f'### {content_id}\n\n```go\n{content}\n```\n\n',file = open('PR_preview.md','a'))
else:
print(f'You do not have permission to get password.\nREF: {environ["GITHUB_REF"]}\nREPO_OWNER: {environ["GITHUB_REPOSITORY_OWNER"]}')
4 changes: 2 additions & 2 deletions TSS.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

today = date.today()

dataset = AllUp_utils.wiki.pull('模板:天宫空间站任务列表/echarts/data')
for row in dataset.split('\n'):
dataset = AllUp_utils.wiki.pull('模板:天宫空间站任务列表/echarts/data',split_line = True)
for row in dataset:
data = row.split(',')
start_date = date.fromisoformat(data[2])
end_date = date.fromisoformat(data[3]) if data[3] != 'future' else date.today()
Expand Down
1 change: 1 addition & 0 deletions test-sources/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
These works by 卫星百科 is licensed under 署名-非商业性使用-相同方式共享 3.0 中国大陆. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/3.0/cn/
13 changes: 13 additions & 0 deletions test-sources/TSS-data.wikitext
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
天和核心舱,main,20210429,future
天舟二号,tz,20210529,20220331
神舟十二号,sz,20210617,20210917
天舟三号,tz,20210920,20220727
神舟十三号,sz,20211016,20220416
天舟四号,tz,20220510,20221115
神舟十四号,sz,20220605,20221204
问天实验舱,main,20220724,future
梦天实验舱,main,20221031,future
天舟五号,tz,20221112,20230912
神舟十五号,sz,20221129,20230604
天舟六号,tz,20230510,future
神舟十六号,sz,20230530,future

0 comments on commit 1274aa0

Please sign in to comment.