kivy 小demo
from kivy.lang.builder import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
import requests
import time
import re
import threading
from kivy.uix.widget import Widget
from kivy.config import Config
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.filechooser import FileChooserListView Config.set('kivy', 'default_font', [
'msgothic',
'DroidSansFallback.ttf']) tem = Builder.load_string('''
<TitleRow>
orientation: 'horizontal'
Label:
text:'name'
Label:
text:'level'
Label:
text:'map'
Label:
text:'attack'
Label:
text:'warn' <DataRow>
name:name
level:level
map:map
attack:attack
warn:warn
orientation: 'horizontal'
Label:
id:name
text:''
Label:
id:level
text:''
Label:
id:map
text:''
Label:
id:attack
text:''
Label:
id:warn
text:'' <SelectFile>
fc:fc
orientation:'vertical'
FileChooserListView
path:'./'
id:fc
size_hint_y:None
height:root.height*0.85
BoxLayout:
orientation:'horizontal'
Button:
size_hint_y:None
height:root.height*0.1
text:'confirm'
on_release:root.confirm(root.fc)
Button:
size_hint_y:None
height:root.height*0.1
text:'cancel'
on_release:root.parent.parent.parent.dismiss() <Check>
name:'check window'
run:run
fileaddr:fileaddr
orientation:'vertical'
TitleRow:
id:row1
DataRow:
id:row2
DataRow:
id:row3
DataRow:
id:row4
DataRow:
id:row5
DataRow:
id:row6
DataRow:
id:row7
DataRow:
id:row8
DataRow:
id:row9
DataRow:
id:row10
DataRow:
id:row11
BoxLayout:
orientation:'horizontal'
Button:
id:run
text:'run'
on_release:self.parent.parent.click(self)
disabled:False
Button:
id:reset
text:'reset'
on_release:self.parent.parent.reset()
Button:
id:fileaddr
size_hint_y:None
height:'40px'
addr:'test_file_addr'
text:'select account file'
on_release:self.parent.select(self)
''') class SelectFile(BoxLayout):
def confirm(self, instance):
file = str(instance.selection[0])
self.parent.parent.parent.parent.children[1].fileaddr.addr = file
self.parent.parent.parent.dismiss() class GetInfo(object):
def __init__(self, txtfile):
super(GetInfo, self).__init__()
with open(txtfile, 'r', encoding='utf-8') as f:
a = f.readlines()
f.close()
self.accounts = []
for account in a:
self.accounts.append(account.strip().split(','))
if len(self.accounts) > 13:
self.accounts = self.accounts[:13]
self.qty = len(self.accounts) def status(self, Check):
for i in range(self.qty):
Check.ids['row' + str(i + 2)].name.text = 'pending'
Check.ids['row' + str(i + 2)].level.text = 'pending'
Check.ids['row' + str(i + 2)].map.text = 'pending'
Check.ids['row' + str(i + 2)].attack.text = 'pending'
Check.ids['row' + str(i + 2)].warn.text = 'pending' def details(self, Check):
self.status(Check)
userinfo = []
for user in self.accounts:
try:
fcsrf = self.getcsrf()
time.sleep(1)
info = self.getinfo(user, fcsrf)
time.sleep(1)
except Exception as e:
info = ''
userinfo.append(eval(info)) results = []
for info in userinfo:
try:
warn = ''
if info['weight'] / info['maxweight'] > 0.5:
warn = warn + 'weight,'
if int(info['hp']) < 2:
warn = warn + 'died,'
if info['autoattack'] != 49:
warn = warn + 'no auto'
if warn == '':
warn = 'ok'
attack = 'yes_auto' if info['autoattack'] == 49 else 'no_auto'
result = [info['name'], info['base_level'], info['last_map'],attack, warn]
except Exception:
result = [None, None, None, None, None]
results.append(result) for i in range(self.qty):
try:
Check.ids['row'+ str(i+2)].name.text = str(results[i][0])
Check.ids['row'+ str(i+2)].level.text = str(results[i][1])
Check.ids['row'+ str(i+2)].map.text = str(results[i][2])
Check.ids['row'+ str(i+2)].attack.text = str(results[i][3])
Check.ids['row'+ str(i+2)].warn.text = str(results[i][4])
except Exception:
Check.ids['row' + str(i+2)].name.text = 'none'
Check.ids['row' + str(i+2)].level.text = 'none'
Check.ids['row' + str(i+2)].map.text = 'none'
Check.ids['row' + str(i+2)].attack.text = 'none'
Check.ids['row' + str(i+2)].warn.text = 'none'
Check.ids.reset.disabled = False
return True def getinfo(self, user, keys):
header = {
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,la;q=0.6,zh-TW;q=0.5',
'AlexaToolbar - ALX_NS_PH': 'AlexaToolbar / alx - 4.0.3',
'Connection': 'keep-alive',
'Cookie': keys[0],
'Content-Length': '125',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Host': 'www.zizi.cn',
'Origin': 'http://www.zizi.cn',
'Referer': 'http://www.zizi.cn/?r=mn/index',
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Mobile Safari/537.36',
}
url = 'http://www.zizi.cn/?r=mn/search'
data = {
'_csrf': keys[1],
'Login[userid]': user[0],
'Login[user_pass]': user[1],
}
response = requests.post(url=url, headers=header, data=data)
content = response.content.decode('utf-8')
return content def getcsrf(self):
url = 'http://www.zizi.cn/?r=mn/index'
index = requests.get(url=url)
cookie = str(index.cookies)
patt = r'\ (.*)\ for'
cookie = re.findall(patt, cookie)[0]
index = index.content.decode('utf-8')
pattern = r'id=\"_csrf\"\ value=\"(.*)\"'
csrf = re.findall(pattern, index)[0]
return [cookie, csrf] class TitleRow(BoxLayout):
pass class DataRow(BoxLayout):
pass class Check(BoxLayout):
def click(self, obj):
file = self.fileaddr.addr
t = threading.Thread(target=GetInfo(file).details, args=[self])
t.start()
self.ids.reset.disabled = True
obj.disabled = True def reset(self):
for i in range(10):
self.ids['row'+str(i+2)].name.text = ''
self.ids['row'+str(i+2)].level.text = ''
self.ids['row'+str(i+2)].map.text = ''
self.ids['row'+str(i+2)].attack.text = ''
self.ids['row'+str(i+2)].warn.text = ''
self.ids.run.disabled = False
self.fileaddr.addr = '' def select(self, instance):
content = SelectFile()
self.popup = Popup(title="select file...", content=content,size_hint=(0.9, 0.9))
self.popup.open() class GameRo(App):
def build(self):
return Check() if __name__ == '__main__':
GameRo().run()
kivy 小demo的更多相关文章
- 新手 gulp+ seajs 小demo
首先,不说废话,它的介绍和作者就不在多说了,网上一百度一大堆: 我在这里只是来写写我这2天抽空对seajs的了解并爬过的坑,和实现的一个小demo(纯属为了实现,高手请绕道); 一.环境工具及安装 1 ...
- Nancy之基于Nancy.Hosting.Self的小Demo
继昨天的Nancy之基于Nancy.Hosting.Aspnet的小Demo后, 今天来做个基于Nancy.Hosting.Self的小Demo. 关于Self Hosting Nancy,官方文档的 ...
- Nancy之基于Nancy.Owin的小Demo
前面做了基于Nancy.Hosting.Aspnet和Nancy.Hosting.Self的小Demo 今天我们来做个基于Nancy.Owin的小Demo 开始之前我们来说说什么是Owin和Katan ...
- Nancy之基于Self Hosting的补充小Demo
前面把Hosting Nancy with ASP.NET.Self Hosting Nancy和Hosting Nancy with OWIN 以demo的形式简单描述了一下. 这篇是为Self H ...
- [Unity3D]做个小Demo学习Input.touches
[Unity3D]做个小Demo学习Input.touches 学不如做,下面用一个简单的Demo展示的Input.touches各项字段,有图有真相. 本项目已发布到Github,地址在(https ...
- Android -- 自定义View小Demo,动态画圆(一)
1,转载:(http://blog.csdn.NET/lmj623565791/article/details/24500107),现在如下图的效果: 由上面的效果图可以看到其实是一个在一个圆上换不同 ...
- Win10 FaceAPI小demo开发问题汇总
Win10 FaceAPI小demo开发问题汇总 最近使用微软牛津计划做一个小demo,使用FaceAPI做一个小应用,实现刷脸的功能.开发的过程中用到几个问题,具体如下: Stream 与IRand ...
- 模仿京东顶部搜索条效果制作的一个小demo
最近模仿京东顶部搜索条效果制作的一个小demo,特贴到这里,今后如果有用到可以参考一下,代码如下 #define kScreenWidth [UIScreen mainScreen].bounds.s ...
- Android学习小Demo一个显示行线的自定义EditText
今天在处理一个EditText的时候,想着把EditText做成像一本作业本上的纸一样,每一行都可以由线条隔开,具体效果如下: 1)最开始的思路 一开始的想法是很简单的,找出每一行的高度,然后一行一行 ...
随机推荐
- 【Scrum】-NO.40.EBook.1.Scrum.1.001-【敏捷软件开发:原则、模式与实践】- Scrum
1.0.0 Summary Tittle:[Scrum]-NO.40.EBook.1.Scrum.1.001-[敏捷软件开发:原则.模式与实践]- Scrum Style:DesignPattern ...
- 数据分析与挖掘 - R语言:多元线性回归
一个简单的例子!环境:CentOS6.5Hadoop集群.Hive.R.RHive,具体安装及调试方法见博客内文档. 线性回归主要用来做预测模型. 1.准备数据集: X Y 0.10 42.0 0.1 ...
- github pages搭建网站(三)
一.个人站点 访问 https://用户名.github.io 搭建步骤 (1)创建个人站点 ->新建仓库(注:仓库名必须是[用户名.github.io]) (2)在仓库下新建index.htm ...
- Dropout正则化和其他方法减少神经网络中的过拟合
1. 什么是Dropout(随机失活) 就是在神经网络的Dropout层,为每个神经元结点设置一个随机消除的概率,对于保留下来的神经元,我们得到一个节点较少,规模较小的网络进行训练. 标准网络和dro ...
- MongoDB--搭建mongodb服务器
此为手动搭建: 可以看到初始化data时所有的数据,和log里已经有日志文件
- (已解决)cocos2d-x 运行时xcode提示错误:"vtable for XXX", referenced from;
vtable/引用和虚函数相关,今天在添加一个层的时候报了这个错误,很低级的错误,忘了实现虚函数了(谨记!!) 若如果实现了虚函数还依然如此的话,可能是创建的时候忘了钩上 -desktop 选项了,把 ...
- recover database noredo时报错ORA-19573
环境: RHEL6.4 + Oracle 11.2.0.4 Primary RAC + Standby RAC 今天发现DG备库归档空间满,清理后发现备库出现GAP,需要从主库做基于SCN的增量备份进 ...
- 48.HTML---Flex 布局教程:实例篇
你会看到,不管是什么布局,Flex往往都可以几行命令搞定. 我只列出代码,详细的语法解释请查阅<Flex布局教程:语法篇>.我的主要参考资料是Landon Schropp的文章和Solve ...
- 9.用js制作静态分页
效果如图: css 代码: #page { text-align: center; } .page { display: inline-block; } .page a { padding: 3px ...
- SpringMVC.入门篇《二》form表单
SpringMVC.入门篇<二>form表单 项目工程结构: 在<springmvc入门篇一.HelloWorld>基础上继续添加代码,新增:FormController.ja ...