当前位置:网站首页>Yyds dry goods inventory hands-on teaching you to carry out the packaging and release of mofish Library (fishing Library)
Yyds dry goods inventory hands-on teaching you to carry out the packaging and release of mofish Library (fishing Library)
2022-07-02 16:10:00 【Python advanced】
Hello everyone , I'm Pippi .
One 、 Preface
A few days ago, boss Wu recommended me a fishing house , Turned out to be Python library , I was surprised , Feeling should be absent from sting .

You know, he has written an article about fishing before , Interested partners , You can go to : Hands teach you how to use Python Create a fishing countdown interface .
Now he made this fishing into a Python library , Articles have been published about the use of this library , You can go to : Take stock of a named fishing Python library , Let's fish together !
I saw in the comment area 【 I little interesting 】 Big guy's message , As shown in the figure below :

It probably means to write your own code , Encapsulated into Python library , Everyone can use that , Here is the arrangement for , This article is about how to package and publish , Let's see !
Two 、 Code
First prepare the code , This code , Previous articles have been shared , No more details here , The code is here .
# -*- coding: utf-8 -*-
import datetime
import click
from zhdate import ZhDate as lunar_date
def get_week_day(date):
week_day_dict = {
0: ' Monday ',
1: ' Tuesday ',
2: ' Wednesday ',
3: ' Thursday ',
4: ' Friday ',
5: ' Saturday ',
6: ' Sunday ',
}
day = date.weekday()
return week_day_dict[day]
def time_parse(today):
distance_big_year = (lunar_date(today.year, 1, 1).to_datetime().date() - today).days
distance_big_year = distance_big_year if distance_big_year > 0 else (
lunar_date(today.year + 1, 1, 1).to_datetime().date() - today).days
distance_5_5 = (lunar_date(today.year, 5, 5).to_datetime().date() - today).days
distance_5_5 = distance_5_5 if distance_5_5 > 0 else (
lunar_date(today.year + 1, 5, 5).to_datetime().date() - today).days
distance_8_15 = (lunar_date(today.year, 8, 15).to_datetime().date() - today).days
distance_8_15 = distance_8_15 if distance_8_15 > 0 else (
lunar_date(today.year + 1, 8, 15).to_datetime().date() - today).days
distance_year = (datetime.datetime.strptime(f"{today.year}-01-01", "%Y-%m-%d").date() - today).days
distance_year = distance_year if distance_year > 0 else (
datetime.datetime.strptime(f"{today.year + 1}-01-01", "%Y-%m-%d").date() - today).days
distance_4_5 = (datetime.datetime.strptime(f"{today.year}-04-05", "%Y-%m-%d").date() - today).days
distance_4_5 = distance_4_5 if distance_4_5 > 0 else (
datetime.datetime.strptime(f"{today.year + 1}-04-05", "%Y-%m-%d").date() - today).days
distance_5_1 = (datetime.datetime.strptime(f"{today.year}-05-01", "%Y-%m-%d").date() - today).days
distance_5_1 = distance_5_1 if distance_5_1 > 0 else (
datetime.datetime.strptime(f"{today.year + 1}-05-01", "%Y-%m-%d").date() - today).days
distance_10_1 = (datetime.datetime.strptime(f"{today.year}-10-01", "%Y-%m-%d").date() - today).days
distance_10_1 = distance_10_1 if distance_10_1 > 0 else (
datetime.datetime.strptime(f"{today.year + 1}-10-01", "%Y-%m-%d").date() - today).days
time_ = [
{"v_": 5 - 1 - today.weekday(), "title": " Over the weekend "}, # From the weekend
{"v_": distance_year, "title": " New year's Day "}, # From New Year's day
{"v_": distance_big_year, "title": " The Chinese New Year "}, # Distance from the Chinese New Year
{"v_": distance_4_5, "title": " Qingming Festival "}, # Distance from Qingming
{"v_": distance_5_1, "title": " labor day "}, # Distance labor
{"v_": distance_5_5, "title": " The Dragon Boat Festival "}, # From the Dragon Boat Festival
{"v_": distance_8_15, "title": " Mid-Autumn Festival "}, # From the Mid Autumn Festival
{"v_": distance_10_1, "title": " National Day "}, # It's national day
]
time_ = sorted(time_, key=lambda x: x['v_'], reverse=False)
return time_
@click.command()
def cli():
""" Hello , Fisherman , I'm tired of work , Don't forget to fish !"""
from colorama import init, Fore
init(autoreset=True) # initialization , And set the color settings to restore automatically
print()
today = datetime.date.today()
now_ = f"{today.year} year {today.month} month {today.day} Japan "
week_day_ = get_week_day(today)
print(f'\t\t {Fore.GREEN}{now_} {week_day_}')
str_ = '''
Hello , Fisherman , I'm tired of work , Don't forget to fish !
If you have nothing to do, get up and go to the tea room, go to the corridor and walk on the roof , Don't always sit on the station .
Drink more water , The money belongs to the boss , But life is your own !
'''
print(f'{Fore.RED}{str_}')
time_ = time_parse(today)
for t_ in time_:
print(f'\t\t {Fore.RED} distance {t_.get("title")} also : {t_.get("v_")} God ')
tips_ = '''
[ Friendship tips ] Third class hospital ICU The average cost of lying down for a day is about 10000 yuan .
You're a day late ICU, It's like making an extra $10000 for your family . Less work , Fish more .\n
'''
print(f'{Fore.RED}{tips_}')
print(f'\t\t\t\t\t\t\t{Fore.YELLOW} Fishing do ')
if __name__ == '__main__':
cli()
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
click Library usage
Notice that our file code above uses click library .
Python There's a built-in Argparse Standard library for creating command line , But it's a little cumbersome to use ,Click Compared with Argparse It can be said that it is a small Witch to see a great witch .
install
pip install click
- 1.
click Simple use
An introductory example of official documents :
import click
@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name', help='The person to greet.')
def hello(count, name):
"""Simple program that greets NAME for a total of COUNT times."""
for x in range(count):
click.echo('Hello %s!' % name)
if __name__ == '__main__':
hello()
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
@click.command()Make functionhelloBecome a command line interface .@click.optionThe first parameter of specifies the name of the command line option .click.echoMethods andpythonBuilt inprintThe method is similar .
Usage method :
Print 10 individual Boss pi .
$ python hello.py --count 10 --name Boss pi # Appoint count and name Value
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
setuptool Packaging releases
Installation dependency
pip install setuptools
pip install twine
- 1.
- 2.
Package and upload
python setup.py sdist
twine upload dist/*
- 1.
- 2.
Sign in pypi Account and publish python library
setup.py Example
from setuptools import setup, find_packages
description = ' Hello , Fisherman , I'm tired of work , Don't forget to fish ! If you have nothing to do, get up and go to the tea room, go to the corridor and walk on the roof , Don't always sit on the station . Drink more water , The money belongs to the boss , But life is your own !'
setup(
name='mofish', # Library name
version='1.0.0', # Version number
description=description, # Short introduction
long_description_content_type='text/markdown',
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Internet',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: System :: Clustering',
'Topic :: System :: Distributed Computing',
'Topic :: System :: Monitoring',
'Topic :: System :: Systems Administration',
],
python_requires='>=3.7', # py Version restrictions
author='PY-GZKY', # author
author_email='[email protected]', # mail
url='https://github.com/PY-GZKY/Mofish', # git
license='MIT', # Open source licenses
packages=find_packages(), # package
include_package_data=True,
entry_points="""
[console_scripts]
moyu=src.main:cli
""", # Start the command line script file
install_requires=[
'click>=6.7',
'zhdate'
], # Limit the version of the installation Library
)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
Install and use
pip install mofish
moyu
- 1.
- 2.
Code warehouse address :
https://github.com/PY-GZKY/Mofish
- 1.

summary
Hello everyone , I'm Pippi . This article is mainly to give you an inventory of Python library , Based on this library , This article introduces how to encapsulate your own code into Python library , Package and upload , And publish it to pypi, Everyone in the back can use your library .
Finally thanks 【 Boss Wu 】 The thought and code support given by the boss , thank 【 I little interesting 】 The needs of the boss .
[ Friendship tips ] Third class hospital ICU The average cost of lying down for a day is about 10000 yuan . You're a day late ICU, It's like making an extra $10000 for your family . Less work , Fish more .

friends , Practice it quickly ! If in the process of learning , Any problems encountered , Welcome to add my friend , I'll pull you in Python The learning exchange group discusses learning together .
边栏推荐
- 【5G NR】RRC连接释放
- 数据湖(十一):Iceberg表数据组织与查询
- Dimension table and fact table in data warehouse
- 死锁的条件及解决方法
- Everyone Xinfu builds: a one-stop intelligent business credit service platform
- End time processing method of wechat v3native payment settings
- Flink real-time data warehouse (IX): incremental synchronization of data in MySQL
- 理想之光不灭
- Various entanglements between qvariant and Jason -- QT
- Traversal before, during and after binary tree
猜你喜欢

华为云服务器安装mysqlb for mysqld.service failed because the control process exited with error code.See “sys

Armv8-a programming guide MMU (4)

解决** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the defau

2020.4.12 byte written test questions B DP D monotone stack

Storage, reading and writing of blood relationship data of Nepal Graph & Data Warehouse

The light of ideal never dies

图数据库|Nebula Graph v3.1.0 性能报告

Recommended practice sharing of Zhilian recruitment based on Nebula graph

win10系统升级一段时间后,内存占用过高

Vscode设置标签页多行显示
随机推荐
The light of ideal never dies
win10系统升级一段时间后,内存占用过高
day4
Experiment collection of University Course "Fundamentals of circuit analysis". Experiment 5 - Research on equivalent circuit of linear active two terminal network
Original God 2.6 server download and installation tutorial
Locate: cannot execute stat() `/var/lib/mlocate/mlocate Db ': there is no such file or directory
Memory alignment of structure
【小白聊云】中小企业容器化改造建议
/Bin/ld: cannot find -lssl
Wise target detection 23 - pytoch builds SSD target detection platform
Armv8-a programming guide MMU (4)
Boot 事务使用
去除router-link中的下划线
纪念成为首个 DAYU200 三方 demo 贡献者
IDEA中设置背景图片(超详细)
Vscade set multi line display of tab
Solve the problem of base64encoder error
源码look me
Route service grid traffic through two-level gateway design
Introduction to dynamic planning I, BFS of queue (70.121.279.200)