Archived
删除历史版本, 初始化仓库
This commit is contained in:
37 files changed
+1773
No files matched your search
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
# -- coding:utf-8 --
|
||||
# @Author: markushammered@gmail.com
|
||||
# @Development Tool: PyCharm
|
||||
# @Create Time: 2022/3/25
|
||||
# @File Name: __init__.py.py
|
||||
|
||||
__all__ = [
|
||||
'response',
|
||||
'password'
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
# -- coding:utf-8 --
|
||||
# @Author: markushammered@gmail.com
|
||||
# @Development Tool: PyCharm
|
||||
# @Create Time: 2022/4/11
|
||||
# @File Name: password.py
|
||||
|
||||
import random
|
||||
|
||||
|
||||
def generate_pwd(length):
|
||||
"""
|
||||
生成随机密码
|
||||
:param length:
|
||||
:return:
|
||||
"""
|
||||
letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
return ''.join(random.choice(letters) for _ in range(length))
|
||||
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
# -- coding:utf-8 --
|
||||
# @Author: markushammered@gmail.com
|
||||
# @Development Tool: PyCharm
|
||||
# @Create Time: 2022/3/25
|
||||
# @File Name: response.py
|
||||
|
||||
|
||||
from ..db.db import SQLite as db
|
||||
from flask import request
|
||||
from flask import render_template
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
def index_(theme: str, length: int, name: str, count: str) -> str or Tuple[bool, str]:
|
||||
"""
|
||||
渲染模板
|
||||
:param theme:
|
||||
:param length:
|
||||
:param name:
|
||||
:param count:
|
||||
:return:
|
||||
"""
|
||||
datas = db().fetching_table(theme)
|
||||
context = []
|
||||
for i in count:
|
||||
if i == '0':
|
||||
context.append({'url': datas[0]['url'],
|
||||
'width': datas[0]['width'],
|
||||
'height': datas[0]['height']})
|
||||
elif i == '1':
|
||||
context.append({'url': datas[1]['url'],
|
||||
'width': datas[1]['width'],
|
||||
'height': datas[1]['height']})
|
||||
elif i == '2':
|
||||
context.append({'url': datas[2]['url'],
|
||||
'width': datas[2]['width'],
|
||||
'height': datas[2]['height']})
|
||||
elif i == '3':
|
||||
context.append({'url': datas[3]['url'],
|
||||
'width': datas[3]['width'],
|
||||
'height': datas[3]['height']})
|
||||
elif i == '4':
|
||||
context.append({'url': datas[4]['url'],
|
||||
'width': datas[4]['width'],
|
||||
'height': datas[4]['height']})
|
||||
elif i == '5':
|
||||
context.append({'url': datas[5]['url'],
|
||||
'width': datas[5]['width'],
|
||||
'height': datas[5]['height']})
|
||||
elif i == '6':
|
||||
context.append({'url': datas[6]['url'],
|
||||
'width': datas[6]['width'],
|
||||
'height': datas[6]['height']})
|
||||
elif i == '7':
|
||||
context.append({'url': datas[7]['url'],
|
||||
'width': datas[7]['width'],
|
||||
'height': datas[7]['height']})
|
||||
elif i == '8':
|
||||
context.append({'url': datas[8]['url'],
|
||||
'width': datas[8]['width'],
|
||||
'height': datas[8]['height']})
|
||||
elif i == '9':
|
||||
context.append({'url': datas[9]['url'],
|
||||
'width': datas[9]['width'],
|
||||
'height': datas[9]['height']})
|
||||
|
||||
for p, i in zip(context, range(0, length)):
|
||||
p['position'] = i * p['width'] # 设置每张图片对应的位置
|
||||
|
||||
general_width = datas[0]['width'] * length # 计算出图片总长度
|
||||
general_height = datas[0]['height'] # 总宽度
|
||||
|
||||
return render_template('view.html',
|
||||
context=context,
|
||||
title=name,
|
||||
address=request.remote_addr,
|
||||
general_height=general_height,
|
||||
general_width=general_width)
|
||||
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
# -- coding:utf-8 --
|
||||
# @Author: markushammered@gmail.com
|
||||
# @Development Tool: Pycharm
|
||||
# @Create Time: 2022/4/29
|
||||
# @File Name: update.py
|
||||
|
||||
|
||||
import os
|
||||
import base64
|
||||
import logging
|
||||
import requests
|
||||
from ..config import VersionConfig
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
class SelfUpdateVersion:
|
||||
"""更新本体 -> 更新单个文件"""
|
||||
|
||||
def __init__(self, logger: logging.Logger):
|
||||
self.api = 'https://api.github.com/repos/MarkusJoe/RequestCounter/tags'
|
||||
self.headers = {'Authorization': 'token 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'}
|
||||
self.resp = requests.get(self.api, headers=self.headers).json()
|
||||
self.logger = logger
|
||||
|
||||
def commit_details(self):
|
||||
"""
|
||||
获取提交细节
|
||||
:return:
|
||||
"""
|
||||
commit_url = self.resp[0]['commit']['url']
|
||||
res = requests.get(commit_url, headers=self.headers).json()
|
||||
files = res['files']
|
||||
modified = []
|
||||
deleted = []
|
||||
|
||||
for f in files:
|
||||
file_path = f['filename']
|
||||
base64_content = requests.get(f['contents_url'], headers=self.headers).json()['content'] # 直接获取修改文件的base64
|
||||
if f['status'] in ['modified', 'added']:
|
||||
modified.append({'filename': f'./{file_path}', 'content': base64.b64decode(base64_content)})
|
||||
else:
|
||||
deleted.append(f'./{file_path}')
|
||||
|
||||
self.apply_change(modified, deleted)
|
||||
|
||||
def apply_change(self, modified: List[Dict], deleted: List):
|
||||
"""
|
||||
应用已经更改的文件
|
||||
:param modified:
|
||||
:param deleted:
|
||||
:return:
|
||||
"""
|
||||
for d in deleted:
|
||||
os.remove(d)
|
||||
self.logger.info(f'删除了: {d}')
|
||||
|
||||
for m in modified:
|
||||
with open(m['filename'], 'wb') as modify:
|
||||
modify.write(m['content'])
|
||||
self.logger.info(f'修改了: {m["filename"]}')
|
||||
|
||||
with open('./app/config.py', 'wb') as update_config:
|
||||
content = requests.get('https://api.github.com/repos/MarkusJoe/RequestCounter/contents/app/config.py',
|
||||
headers=self.headers).json()['content']
|
||||
update_config.write(base64.b64decode(content))
|
||||
|
||||
exit()
|
||||
|
||||
def check(self):
|
||||
current = VersionConfig.version[0]
|
||||
newest = self.resp[0]['name']
|
||||
if current != newest:
|
||||
self.logger.warning(f'当前版本已经落后于最新版本. 当前: {current} -> 远程: {newest}')
|
||||
self.commit_details()
|
||||
return False
|
||||
else:
|
||||
self.logger.info('当前版本为最新版本')
|
||||
return True
|
||||
Reference in New Issue
Block a user