I would like to build a simple Kivy app that:
我想构建一个简单的Kivy应用程序:
- Asks the user to input an integer (MTP)
- Asks the user to input a delay interval (delay)
- Queries a url after the user presses a submit button and then from the query creates a pandas dataframe that is displayed (like a table) on the main screen of the Kivy app and then the output dataframe is updated until the MTP and delay interval are up
要求用户输入整数(MTP)
要求用户输入延迟间隔(延迟)
在用户按下提交按钮后查询URL,然后从查询中创建在Kivy应用程序主屏幕上显示的pandas数据框(如表),然后更新输出数据帧,直到MTP和延迟间隔为止
I have all the code functioning for the query as a regular python program, I just don't know how to have the user input and the output dataframe (and a time stamp) displayed. (See below)
我将查询的所有代码作为常规python程序运行,我只是不知道如何显示用户输入和输出数据帧(以及时间戳)。 (见下文)
import requests
import time
from bs4 import BeautifulSoup
from datetime import datetime
import itertools
import pandas as pd
mtp = input("Input whole number of minutes to post:") #<-How to do on Kivy Screen
delay = input("Enter 15, 30 or 60 second delay:") #<-How to ask on Kivy Screen
STP = int(mtp)*60
def requestOdds():
url = "https://WEBPAGE WITH ODDS DATA.aspx"
r = requests.get(url)
soup = BeautifulSoup(r.content)
stamp = datetime.now().strftime('%m/%d %H:%M:%S')
tbPPosts = ('rptOdds_ctl01_tdOdd', 'rptOdds_ctl02_tdOdd','rptOdds_ctl03_tdOdd','rptOdds_ctl04_tdOdd','rptOdds_ctl05_tdOdd','rptOdds_ctl06_tdOdd','rptOdds_ctl07_tdOdd','rptOdds_ctl08_tdOdd','rptOdds_ctl09_tdOdd','rptOdds_ctl10_tdOdd','rptOdds_ctl11_tdOdd','rptOdds_ctl12_tdOdd','rptOdds_ct113_tdOdd','rptOdds_ct114_tdOdd','rptOdds_ct115_tdOdd','rptOdds_ct116_tdOdd','rptOdds_ct117_tdOdd','rptOdds_ct118_tdOdd','rptOdds_ct119_tdOdd','rptOdds_ct120_tdOdd','rptOdds_ct121_tdOdd')
mlPPosts = ('rptOdds_ctl01_tdMl','rptOdds_ctl02_tdMl','rptOdds_ctl03_tdMl','rptOdds_ctl04_tdMl','rptOdds_ctl05_tdMl','rptOdds_ctl06_tdMl','rptOdds_ctl07_tdMl','rptOdds_ctl08_tdMl','rptOdds_ctl09_tdOdd','rptOdds_ctl10_tdMl','rptOdds_ctl11_tdMl','rptOdds_ctl12_tdMl','rptOdds_ct113_tdMl','rptOdds_ct114_tdMl','rptOdds_ct115_tdMl','rptOdds_ct116_tdMl', 'rptOdds_ct117_tdMl','rptOdds_ct118_tdMl','rptOdds_ct119_tdMl','rptOdds_ct120_tdMl','rptOdds_ct121_tdMl')
trimmed_text=[]
trimmed_text2=[]
tbodds = []
mlodds = []
odds = []
for horse in tbPPosts:
table = soup.find('td', {"odds-table-odd"}, id=horse)
if table is not None:
text = table.renderContents()
trimmed_text = text.strip()
tbodds.append(trimmed_text)
for mlhorse in mlPPosts:
table2 = soup.find('td', {"odds-table-ml"}, id=mlhorse)
if table2 is not None:
text2 = table2.renderContents()
trimmed_text2 = text2.strip()
mlodds.append(trimmed_text2)
mlodds = itertools.ifilterfalse(lambda x: x=='', mlodds) #faster
tbodds = itertools.ifilterfalse(lambda x: x=='', tbodds)
oddsDict = dict(zip(mlodds, tbodds))
**odds = pd.DataFrame(list(oddsDict.iteritems()), columns=['ML','TB'])
print odds, stamp** #<--How do I get these to print onto the Kivy Screen?
def getLiveOdds():
interval = 0
while interval <= STP:
requestOdds()
time.sleep(delay)
interval +=delay
getLiveOdds()
Any help would be greatly appreciated!
任何帮助将不胜感激!
1 个解决方案
#1
2
I found out something which could help you :
我找到了可以帮助你的东西:
Kivy file
GraphDraw:
<GraphDraw>:
BoxLayout:
Button:
text: "Hello World"
on_press: root.graph()
Logic
#!/usr/bin/env python
# -*- encoding: utf-8
import datetime
import pandas as pd
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import dfgui
import pandas as pd
class Visualisation(App):
pass
class GraphDraw(BoxLayout):
def graph(self):
xls = pd.read_excel('filepath')
#df = pd.DataFrame.xls
dfgui.show(xls)
#print xls
if __name__ == '__main__':
Visualisation().run()
So you use dfgui which can create pandas dataframe table instead of using Kivy. See the project dfgui : https://github.com/bluenote10/PandasDataFrameGUI
所以你使用dfgui可以创建pandas dataframe表而不是使用Kivy。请参阅项目dfgui:https://github.com/bluenote10/PandasDataFrameGUI
I hope it can help :)
我希望它可以帮助:)
#1
2
I found out something which could help you :
我找到了可以帮助你的东西:
Kivy file
GraphDraw:
<GraphDraw>:
BoxLayout:
Button:
text: "Hello World"
on_press: root.graph()
Logic
#!/usr/bin/env python
# -*- encoding: utf-8
import datetime
import pandas as pd
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import dfgui
import pandas as pd
class Visualisation(App):
pass
class GraphDraw(BoxLayout):
def graph(self):
xls = pd.read_excel('filepath')
#df = pd.DataFrame.xls
dfgui.show(xls)
#print xls
if __name__ == '__main__':
Visualisation().run()
So you use dfgui which can create pandas dataframe table instead of using Kivy. See the project dfgui : https://github.com/bluenote10/PandasDataFrameGUI
所以你使用dfgui可以创建pandas dataframe表而不是使用Kivy。请参阅项目dfgui:https://github.com/bluenote10/PandasDataFrameGUI
I hope it can help :)
我希望它可以帮助:)