3 Star 0 Fork 1

mirrors_sjqzhang / meican

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

MeiCan 美餐

PyPI Build

同时支持 Python 3.6+ 与命令行调用的美餐点餐非官方库

山上的朋友! 树上的朋友! 有选择困难症的朋友! 每周都忘记点饭的朋友! 每天都想点同一个套餐的朋友!

:ghost: 懒人们! 快快解放双手来点美餐吧~

背景

最开始是因为我司用的美餐服务, 所以就写了个命令行脚本内部点餐用。

后来发现其实大家会有自己动手实现点单逻辑的需求, 就做成了这个开源库啦。

安装

通过pip:

pip install meican

代码调用

from meican import MeiCan, MeiCanLoginFail, NoOrderAvailable

try:
    meican = MeiCan('username@domain', 'hunter2')  # login
    dishes = meican.list_dishes()
    if any(dish for dish in dishes if dish.name == '香酥鸡腿'):
        print('今天有香酥鸡腿 :happy:')
    else:
        print('今天没有香酥鸡腿 :sad:')
except NoOrderAvailable:
    print('今天没有开放点餐')
except MeiCanLoginFail:
    print('用户名或者密码不正确')

自动点餐示例

#!/usr/bin/env pytho
# -*- coding:utf-8 -*-
import random
from meican import MeiCan, MeiCanLoginFail, NoOrderAvailable
from meican.settings import *

mc = MeiCan


def initialize_meican():
    global mc
    settings = MeiCanSetting()
    settings.load_credentials()
    mc = MeiCan(settings.username, settings.password)
    mc.load_tabs()
    return mc


def order_random(tab_keyword, keyword):
    try:
        dishes = get_tab_dishes(tab_keyword)
        if keyword != "":
            dishes2 = list(filter(lambda d: str(d.name).find(keyword) != -1, dishes))
            if len(dishes2) > 0:
                dishes = dishes2
        rid = random.randint(0, len(dishes) - 1)
        mc.order(dishes[rid])
    except Exception as er:
        print(er)


def get_tab_dishes(tab_keyword):
    global mc
    tab = None
    for _tab in mc.tabs:
        if str(_tab.title).find(str(tab_keyword)) != -1:
            tab = _tab
            break
    dishes = mc.list_dishes(tab)
    return dishes


if __name__ == '__main__':
    initialize_meican()
    # order_random('楼层关键字','套餐关键字')
    order_random('26', '不辣')
package main

import (
	"fmt"
	"github.com/robfig/cron"
	"os/exec"
)

func order() {

	cmd := exec.Command("/usr/local/bin/meican")
	output, err := cmd.Output()
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(string(output))
	}

}

func main() {
	c := cron.New()
	spec := "50 11 * * MON-FRI"
	_, err := c.AddFunc(spec, func() {
		go order()
	})
	if err != nil {
		panic(err)
	}
	c.Start()

	select {}
}

命令行调用

meican  # 查询下次点啥菜
meican -o 香酥  # 点包含 香酥 关键字的菜,比如香酥鸡腿

贡献

不论是任何疑问、想要的功能还是想吃的套餐都欢迎直接提 issue

假如你们公司是用熙香点餐的, 隔壁也有熙香的库噢~

:wink: 欢迎各种 PR

协议

宽松的 MIT 协议:

  • ✔ 支持各种改写
  • ✔ 支持你把代码作者都改成自己
  • ✖ 不支持每天中午免费吃西贝莜面村
  • ✖ 也不支持点大羊腿、掌中宝
MIT License Copyright (c) 2017 Lirian Su Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
Python
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/mirrors_sjqzhang/meican.git
git@gitee.com:mirrors_sjqzhang/meican.git
mirrors_sjqzhang
meican
meican
master

搜索帮助