要知道之前他就已经写了一篇关于摸鱼的文章,感兴趣的小伙伴,可以前往:手把手教你使用Python打造一款摸鱼倒计界面。
我们提供的服务有:成都做网站、网站制作、成都外贸网站建设、微信公众号开发、网站优化、网站认证、萨嘎ssl等。为上千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的萨嘎网站制作公司
如今他把这个摸鱼做成了一个Python库,关于这个库的使用之前已经发布了文章,可以前往:盘点一个名为摸鱼的Python库,一起来摸鱼吧!
在评论区看到了【有点意思】大佬的留言,如下图所示:
大概意思是把自己写的代码,封装成Python库,人人都可用那种,这里给安排上,这篇文章就是讲如何打包发布的,一起来看看吧!
首先准备好代码,这个代码,之前的文章就已经分享了,这里不再赘述,代码在这里了。
# -*- coding: utf-8 -*-
import datetime
import click
from zhdate import ZhDate as lunar_date
def get_week_day(date):
week_day_dict = {
0: '星期一',
1: '星期二',
2: '星期三',
3: '星期四',
4: '星期五',
5: '星期六',
6: '星期天',
}
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": "周末"}, # 距离周末
{"v_": distance_year, "title": "元旦"}, # 距离元旦
{"v_": distance_big_year, "title": "过年"}, # 距离过年
{"v_": distance_4_5, "title": "清明节"}, # 距离清明
{"v_": distance_5_1, "title": "劳动节"}, # 距离劳动
{"v_": distance_5_5, "title": "端午节"}, # 距离端午
{"v_": distance_8_15, "title": "中秋节"}, # 距离中秋
{"v_": distance_10_1, "title": "国庆节"}, # 距离国庆
]
time_ = sorted(time_, key=lambda x: x['v_'], reverse=False)
return time_
@click.command()
def cli():
"""你好,摸鱼人,工作再累,一定不要忘记摸鱼哦 !"""
from colorama import init, Fore
init(autoreset=True) # 初始化,并且设置颜色设置自动恢复
print()
today = datetime.date.today()
now_ = f"{today.year}年{today.month}月{today.day}日"
week_day_ = get_week_day(today)
print(f'\t\t {Fore.GREEN}{now_} {week_day_}')
str_ = '''
你好,摸鱼人,工作再累,一定不要忘记摸鱼哦 !
有事没事起身去茶水间去廊道去天台走走,别老在工位上坐着。
多喝点水,钱是老板的,但命是自己的 !
'''
print(f'{Fore.RED}{str_}')
time_ = time_parse(today)
for t_ in time_:
print(f'\t\t {Fore.RED}距离{t_.get("title")}还有: {t_.get("v_")}天')
tips_ = '''
[友情提示] 三甲医院 ICU 躺一天平均费用大概一万块。
你晚一天进 ICU,就等于为你的家庭多赚一万块。少上班,多摸鱼。\n
'''
print(f'{Fore.RED}{tips_}')
print(f'\t\t\t\t\t\t\t{Fore.YELLOW} 摸鱼办')
if __name__ == '__main__':
cli()
注意到我们上面的文件代码用到了 click 库。
Python 内置了一个 Argparse 的标准库用于创建命令行, 但使用起来有些繁琐,Click 相比于 Argparse 可谓是小巫见大巫了。
pip install click
官方文档的入门例子:
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()
使用方法:
打印 10 个 皮老板。
$ python hello.py --count 10 --name 皮老板 # 指定 count 和 name 的值
Hello 皮老板!
Hello 皮老板!
Hello 皮老板!
Hello 皮老板!
Hello 皮老板!
Hello 皮老板!
Hello 皮老板!
Hello 皮老板!
Hello 皮老板!
Hello 皮老板!
pip install setuptools
pip install twine
python setup.py sdist
twine upload dist/*
登录 pypi 账户并发布 python 库
from setuptools import setup, find_packages
description = '你好,摸鱼人,工作再累,一定不要忘记摸鱼哦! 有事没事起身去茶水间去廊道去天台走走,别老在工位上坐着。多喝点水,钱是老板的,但命是自己的!'
setup(
name='mofish', # 库名
version='1.0.0', # 版本号
description=description, # 短简介
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 版本限制
author='PY-GZKY', # 作者
author_email='341796767@qq.com', # 邮件
url='https://github.com/PY-GZKY/Mofish', # git
license='MIT', # 开源协议
packages=find_packages(), # 包
include_package_data=True,
entry_points="""
[console_scripts]
moyu=src.main:cli
""", # 启动命令行脚本的文件
install_requires=[
'click>=6.7',
'zhdate'
], # 限制安装库的版本
)
pip install mofish
moyu
代码仓库地址:
https://github.com/PY-GZKY/Mofish
大家好,我是皮皮。这篇文章主要是给大家盘点了一个Python库,基于这个库,本文介绍了如何把自己写的代码封装成Python库,打包上传,并且发布到pypi,到后面人人都可以用你的库。
本文转载自微信公众号「Python爬虫与数据挖掘」,可以通过以下二维码关注。转载本文请联系Python爬虫与数据挖掘公众号。
文章名称:手把手教你开展Mofish库(摸鱼库)的打包发布
文章URL:http://www.stwzsj.com/qtweb/news17/10067.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联