-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create setup.py and add bot apis #6
Open
jackw1997
wants to merge
5
commits into
main
Choose a base branch
from
haphai2205021
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,9 @@ outputs/* | |
dataset/* | ||
*.pyc | ||
.idea | ||
venv | ||
venv | ||
|
||
# package build | ||
build/* | ||
dist/* | ||
group_purchase.egg-info/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include README.md | ||
include group_purchase\assets\html_format.css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,45 @@ | ||
# JuWeiHui | ||
Currently a very ugly but usable script to covert group purchase results to printable sheets for delivery during the pandemic in Shanghai | ||
|
||
Currently a very ugly but usable script to covert group purchase results to printable sheets for delivery during the | ||
pandemic in Shanghai | ||
|
||
## How to use | ||
1. Define your own personal community logic in the community_hardcode folder. Import this class in main.py and change the class name. | ||
|
||
1. Define your own personal community logic in the community_hardcode folder. Import this class in main.py and change | ||
the class name. | ||
2. Create 2 folders files and outputfiles. | ||
3. Put all the files you what to generate in files folder. | ||
3. Put all the files you what to generate in files folder. | ||
4. Run main.py | ||
5. If your file has some missind data, an error will be thrown. Ask the one with missing data to fill the data here. | ||
6. The latex pdf file will be generated in outputfiles folder | ||
|
||
## Other points | ||
|
||
This repo is more like a hardcode repo to solve temporary problems of the JuWeiHui package delivery. We might have more types of excel templates, more communities involved. So it will be appreciate if you can help me to make it less hardcode, and more applicable for more situations. | ||
This repo is more like a hardcode repo to solve temporary problems of the JuWeiHui package delivery. We might have more | ||
types of excel templates, more communities involved. So it will be appreciate if you can help me to make it less | ||
hardcode, and more applicable for more situations. | ||
|
||
Users of this form might touch personal data of the purchaser. For me I will delete all those data when the pandemic is | ||
done, and won't send any such data to anyone else. Please make similar declairation if you need to use this script. | ||
|
||
I would like to add some algorithm-based features to even improve the delivery logic. If you are a specialist in | ||
optimization, please contact me. Wechat id:wgzjack0305 | ||
|
||
--- | ||
|
||
# 订单excel处理方法 | ||
|
||
1. 先指定小区和excel模板,小区用对象(以后这个对象是全局的,生命周期很长),模板用类(模板对象生命周期很短,处理完就销毁了) | ||
2. 指定输入和输出文件名。输入和输出文件名应和需求名有关,输入模板和输出模板会依赖这个。 | ||
3. 调用接口处理excel | ||
1. 创建parser实例,一个parser对应一个excel文件 | ||
2. 调用parser解析接口,返回订单集合对象和出错单元格坐标 | ||
3. 按需生成pdf或提示用户检查原表格数据 | ||
|
||
Users of this form might touch personal data of the purchaser. For me I will delete all those data when the pandemic is done, and won't send any such data to anyone else. Please make similar declairation if you need to use this script. | ||
获取excel模板接口:`get_excel_parser(name: str) -> Optional[Type[ExcelParserBase]]` | ||
|
||
I would like to add some algorithm-based features to even improve the delivery logic. If you are a specialist in optimization, please contact me. Wechat id:wgzjack0305 | ||
- 输入:`name`模板的中文名。 | ||
- 输出:模板的Parser类。找不到该名称对应的模板时返回None。 | ||
- 当前支持模板: | ||
- 群接龙 | ||
- 快团团 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
name = "group_purchase" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from .bot import on_file, update_file | ||
|
||
__all__ = [ | ||
'on_file', | ||
'update_file' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
from group_purchase.community.parser_mng import get_community_parser | ||
from group_purchase.purchase_deliver.parser_mng import get_excel_parser | ||
|
||
import openpyxl | ||
|
||
def on_file(input_file_path, output_file_path, community, excel): | ||
excel_parser = get_excel_parser(excel) | ||
community_parser = get_community_parser(community) | ||
|
||
parser = excel_parser(open(input_file_path, 'rb')) | ||
result, errors = parser.parse_for_community(community_parser()) | ||
if errors: | ||
return f"以下单元格数据无法识别,请检查:\n{errors}" | ||
else: | ||
pass | ||
|
||
result.print_to_pdf(output_file_path) | ||
return output_file_path | ||
|
||
|
||
def update_file(input_file_path, updated_data, coordinate): | ||
try: | ||
workbook = openpyxl.load_workbook(open(input_file_path, 'rb')) | ||
sheet = workbook.active | ||
sheet[coordinate].value = updated_data | ||
workbook.save(input_file_path) | ||
return True | ||
except Exception as error: | ||
print(f"Cannot modify file {input_file_path}, error:\n {error}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这条错误信息调用者get不到,这个只在后台打印还是需要用户感知一下? |
||
return False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .jia_yi_shui_an import JiaYiShuiAn | ||
|
||
__all__ = [ | ||
'JiaYiShuiAn' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from typing import * | ||
|
||
from .community_base import CommunityBase | ||
from .jia_yi_shui_an import JiaYiShuiAn | ||
|
||
parser_map: Mapping[str, Type[CommunityBase]] = { | ||
'嘉怡水岸': JiaYiShuiAn, | ||
} | ||
|
||
|
||
def get_community_parser(name: str) -> Optional[Type[CommunityBase]]: | ||
return parser_map.get(name, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .parser_mng import get_excel_parser | ||
|
||
__all__ = [ | ||
'get_excel_parser' | ||
] |
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
src/PurchaseDeliver/ExcelParser.py → ...hase_deliver/excel_parser/excel_parser.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
src/PurchaseDeliver/ExcelParser1.py → ...se_deliver/excel_parser/jielong_parser.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import * | ||
from collections import defaultdict | ||
from group_purchase.community.community_base import CommunityAddress | ||
|
||
|
||
class Order: | ||
def __init__(self): | ||
self.buyer_name: str = '' | ||
self.address: Optional[CommunityAddress] = None | ||
self.items: defaultdict[str, int] = defaultdict(int) | ||
|
||
def set_buyer(self, buyer: str) -> 'Order': | ||
self.buyer_name = buyer | ||
return self | ||
|
||
def set_address(self, address: CommunityAddress) -> 'Order': | ||
self.address = address | ||
return self | ||
|
||
def set_item(self, item_name: str, amount: int) -> 'Order': | ||
self.items[item_name] = amount | ||
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from typing import * | ||
|
||
from .excel_parser.excel_parser import ExcelParserBase | ||
from .excel_parser.jielong_parser import JieLongParser | ||
from .excel_parser.kuaituantuan_parser import KuaiTuanTuanParser | ||
|
||
parser_map: Mapping[str, Type[ExcelParserBase]] = { | ||
'群接龙': JieLongParser, | ||
'快团团': KuaiTuanTuanParser | ||
} | ||
|
||
|
||
def get_excel_parser(name: str) -> Optional[Type[ExcelParserBase]]: | ||
return parser_map.get(name, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__all__ = [] |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import pdfkit | ||
|
||
|
||
# TODO: 写的有点草率,之后再斟酌下。。。 | ||
def html_string_to_pdf(html, filename): | ||
|
||
pdfkit.from_string(html, filename, configuration=pdfkit.configuration( | ||
wkhtmltopdf=r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe'), options={ | ||
'encoding': 'utf-8', | ||
'user-style-sheet': 'assets/html_format.css', | ||
'user-style-sheet': 'group_purchase/assets/html_format.css', | ||
'footer-center': '第[page]页 共[topage]页' | ||
}) |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
返回失败和成功的类型都是str,调用者如何分辨这是成功后生成的路径还是错误提示信息呢?