当前位置:网站首页>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 functionhello
Become a command line interface .@click.option
The first parameter of specifies the name of the command line option .click.echo
Methods andpython
Built inprint
The 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 .
边栏推荐
- 构建多架构镜像的最佳实践
- [solution] educational codeforces round 82
- Experiment collection of University "Fundamentals of circuit analysis". Experiment 4 - Research on linear circuit characteristics
- [fluent] dart language (DART language features | JIT instant compilation | AOT static compilation)
- (practice C language every day) the sum of the nearest three numbers
- Boot transaction usage
- Target detection - make your own deep learning target detection data set with labelimg
- Locate: cannot execute stat() `/var/lib/mlocate/mlocate Db ': there is no such file or directory
- 智联招聘的基于 Nebula Graph 的推荐实践分享
- What is Amazon keyword index? The consequences of not indexing are serious
猜你喜欢
处理gzip: stdin: not in gzip formattar: Child returned status 1tar: Error is not recoverable: exitin
Idea jar package conflict troubleshooting
Pandora IOT development board learning (RT thread) - Experiment 2 RGB LED experiment (learning notes)
JS learning notes - process control
Construction and business practice of Zhongke brain knowledge map platform
Dimension table and fact table in data warehouse
Vscode设置标签页多行显示
Solve * * warning * *: your ApplicationContext is unlikely to start due to a @componentscan of the defau
The outline dimension function application of small motherboard
Vscade set multi line display of tab
随机推荐
The outline dimension function application of small motherboard
Various entanglements between qvariant and Jason -- QT
win10系统升级一段时间后,内存占用过高
Vscade set multi line display of tab
Xpt2046 four wire resistive touch screen
AWS virtual machine expansion
图数据库|Nebula Graph v3.1.0 性能报告
结构体的内存对齐
Leetcode --- longest public prefix
Route service grid traffic through two-level gateway design
Lseek error
Aike AI frontier promotion (7.2)
Group by的用法
The light of ideal never dies
Maui学习之路(三)--Winui3深入探讨
可视化技术在 Nebula Graph 中的应用
Invalid bound statement (not found)解决方法总结
mysql min() 求某条件下最小的值出现多个结果
请问怎么在oracle视图中使用stustr函数
Locate: cannot execute stat() `/var/lib/mlocate/mlocate Db ': there is no such file or directory