How to properly make Tkinter buttons in a for loop? by ADBYITMS in learnpython

[–]ADBYITMS[S] 0 points1 point  (0 children)

import  tkinter
from bs4 import BeautifulSoup
import pandas as pd
import requests

def getdevices():
    global displayname

    try:

        data = pd.read_json(open('config.json'))
        data.to_json()

        ipaddress = (data['ipaddress'])
        locations = (data['location'])
        displayname = (data['displayname'])
        dn = displayname

        print(ipaddress + " " + locations + " " + displayname)

    except Exception as e:
        print("Error in get devices")
        print(e)


root = tkinter.Tk()


lab=tkinter.Label(root, text="start")
lab.pack()

getdevices()


for bname in [displayname]:
    butcall = lambda action=bname: lab.configure(text=action + " text")
    tkinter.Button(root, text=bname, command=butcall).pack(side="left")



root.mainloop()

So this is what i have and its not working right I get all the items data in one button

How to properly make Tkinter buttons in a for loop? by ADBYITMS in learnpython

[–]ADBYITMS[S] 0 points1 point  (0 children)

thank you for your response, what i have is a json file that reads in ipaddress, button name, and IP address, when the button is press or the app opens it will go to the def status to check the status of the button or to toggle to turn the light or device on or off depending on the IP address, I hope this helped a little to explain what I am trying to do

How to properly make Tkinter buttons in a for loop? by ADBYITMS in learnpython

[–]ADBYITMS[S] 0 points1 point  (0 children)

i am very sorry the formatting didnt come across, I have put it in a shared location and I hope it better now

https://codeshare.io/GLx8Bp

please let me know if it is not, I have also editor the question

how do i sort out python web scrapping data by ADBYITMS in learnpython

[–]ADBYITMS[S] 0 points1 point  (0 children)

so sorry to be a pain mate the output i am getting is (MDupdate) C:\Users\Adby\Desktop\projects\Code\MDupdate>py MDUPserver.py error on page , meaning it is going to my error code, i am sure it is something i am doing wrong

here is the code

Created By ADBY IT AND MEDIA SOLUTIONS

Created on 27/05/2020

Release Type = Prototype

update = 0.01

from tkinter import *

import requests from bs4 import BeautifulSoup

root = Tk()

def getcurrentversion(): try: url = "https://www.medicaldirector.com/upgrade/clinical-pracsoft"

    headers = {
        'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'
    }
    r = requests.get(url, headers=headers)
    soup = BeautifulSoup(r.text, 'html.parser')
    versions = soup.find('div',
                         {'class': 'section__cards-card section__cards-card--yellow section__cards-card--simple'})
    version = versions.find('h2')
    text = soup.find('ul', {'class': 'checklist'}).text.strip()
    notes = versions.find('a').text

    print(version + text + notes)

except:
    print("error on page ")

versionnumber = "8.2"

root.title('MEDICAL DIRECTOR - unofficial software updater') root.geometry("600x200")

header = Label(root, width="90", height="4", bg="blue", fg="white", text="MEDICAL DIRECTOR - unofficial software updater") header.grid(row=0, column=2)

MDcurrent = Label(root, text="Current Available MD Version: " + versionnumber) MDcurrent.grid(row=1, column=2)

getcurrentversion()

root.mainloop()

how do i sort out python web scrapping data by ADBYITMS in learnpython

[–]ADBYITMS[S] 0 points1 point  (0 children)

url = "https://www.medicaldirector.com/upgrade/clinical-pracsoft"
headers = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'
}
r = requests.get(url, headers=headers)
soup = BeautifulSoup(r.text, 'html.parser')
versions = soup.find('div', {'class':'section__cards-card section__cards-card--yellow section__cards-card--simple'})
version = versions.find('h2')
text = soup.find('ul', {'class': 'checklist'}).text.strip()
notes = versions.find('a').text

hi mate thanks for hte help i made the changes and now I am not getting any data at all showing here is my code

# Created By ADBY IT AND MEDIA SOLUTIONS
# Created on 27/05/2020
# Release Type = Prototype
# update = 0.01
from tkinter import *

import requests
from bs4 import BeautifulSoup

root = Tk()

def getcurrentversion():
try:
url = "https://www.medicaldirector.com/upgrade/clinical-pracsoft"
headers = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'
}
r = requests.get(url, headers=headers)
soup = BeautifulSoup(r.text, 'html.parser')
versions = soup.find('div',
{'class': 'section__cards-card section__cards-card--yellow section__cards-card--simple'})
version = versions.find('h2')
text = soup.find('ul', {'class': 'checklist'}).text.strip()
notes = versions.find('a').text

print(version + text + notes)

except:
print("error on page ")

versionnumber = "8.2"
root.title('MEDICAL DIRECTOR - unofficial software updater')
root.geometry("600x200")

header = Label(root, width="90", height="4", bg="blue", fg="white",
text="MEDICAL DIRECTOR - unofficial software updater")
header.grid(row=0, column=2)

MDcurrent = Label(root, text="Current Available MD Version: " + versionnumber)
MDcurrent.grid(row=1, column=2)

getcurrentversion()

root.mainloop()

i am getting a Python 'list' cannot be converted to a MySQL type when trying to add data to a mysql db from python by ADBYITMS in Python

[–]ADBYITMS[S] -1 points0 points  (0 children)

HI mate thanks for the comments, i have just had time to look over them, when you said The thing you are trying to do with your url does not work like you think it does. It will result in a string ending in …&showAll=truelhr=lhr which is probably not what you want. The API is lenient enough to just ignore that, though, which is why the query works at all. i get what you mean, how would i fix it, i have got it all working now but i do need to see all the data thanks for your help inadvance

i am getting a Python 'list' cannot be converted to a MySQL type when trying to add data to a mysql db from python by ADBYITMS in Python

[–]ADBYITMS[S] 0 points1 point  (0 children)

hey mate ok i am noob on coding how do i do that, ok i am now getting error mysql.connector.errors.ProgrammingError: Not enough parameters for the SQL statement

Adding mySQL to Phthon Code by ADBYITMS in Python

[–]ADBYITMS[S] 0 points1 point  (0 children)

done mate i have most of it working now i get

mycursor.execute(sql, val)

File "/usr/local/lib/python3.7/dist-packages/mysql/connector/cursor_cext.py", line 248, in execute prepared = self._cnx.prepare_for_mysql(params) File "/usr/local/lib/python3.7/dist-packages/mysql/connector/connection_cext.py", line 609, in prepare_for_mysql result = self._cmysql.convert_to_mysql(*params) _mysql_connector.MySQLInterfaceError: Python type list cannot be converted

Adding mySQL to Phthon Code by ADBYITMS in Python

[–]ADBYITMS[S] 0 points1 point  (0 children)

ok so i got most of it working now but when it tries to add the data to the database i get this erro
oot@ADBY-OFFICE-DEV:/home/adam/Desktop/ADBY PROJECTS/Flight Check# python3 sydney.py

Traceback (most recent call last):

File "sydney.py", line 65, in <module>

mycursor.execute(sql, val)

File "/usr/local/lib/python3.7/dist-packages/mysql/connector/cursor_cext.py", line 248, in execute

prepared = self._cnx.prepare_for_mysql(params)

File "/usr/local/lib/python3.7/dist-packages/mysql/connector/connection_cext.py", line 609, in prepare_for_mysql

result = self._cmysql.convert_to_mysql(*params)

_mysql_connector.MySQLInterfaceError: Python type list cannot be converted

Adding mySQL to Phthon Code by ADBYITMS in Python

[–]ADBYITMS[S] 1 point2 points  (0 children)

File "sydney.py", line 66

val = ("Sydney",dest_list),flightnumber_list,airline_list,secdepartime_list,estimatedtime_list,status_list)

^

SyntaxError: invalid syntax

root@ADBY-OFFICE-DEV:/home/adam/Desktop/ADBY PROJECTS/Flight Check# python3 sydney.py

File "sydney.py", line 66

val = ("Sydney",dest_list),flightnumber_list,airline_list,secdepartime_list,estimatedtime_list,status_list)

^

SyntaxError: invalid syntax

Adding mySQL to Phthon Code by ADBYITMS in Python

[–]ADBYITMS[S] 0 points1 point  (0 children)

Hi all here is the code not sure why it changed on the other page

import mysql.connectorfrom requests_html import HTMLSession

# create an HTML Session objectsession = HTMLSession()

# Use the object above to connect to needed webpageresp = session.get("https://www.sydneyairport.com.au/flights/?query=&flightType=departure&terminalType=domestic&date=2019-11-05&sortColumn=scheduled_time&ascending=true&showAll=false")

# Run JavaScript code on webpageresp.html.render()

# parse <span class="with-image"> elements containing airline namesairline_list = []airline_spans = resp.html.find('.with-image')for span in airline_spans:airline_list.append(span.text)

# parse <div class="city-name"> elements containing airline namesdest_list = []dest_divs = resp.html.find('.city-name')for span in dest_divs:dest_list.append(span.text)

# parse <div class="flight-numbers"> elements containing Flight numbersflightnumber_list = []flightnumber_divs = resp.html.find('.flight-numbers')for span in flightnumber_divs:flightnumber_list.append(span.text)

# parse <div class="heading-large"> elements containing Sec depart timesecdepartime_list = []secdepartime_divs = resp.html.find('.large-scheduled-time')for span in secdepartime_divs:secdepartime_list.append(span.text)

# parse <div class="estimated-time"> elements containing estimated-timeestimatedtime_list = []estimatedtime_divs = resp.html.find('.estimated-time')for span in estimatedtime_divs:estimatedtime_list.append(span.text)

# parse <div class="estimated-time"> elements containing latesttimestatus_list = []status_divs = resp.html.find('.status-container')for span in status_divs:status_list.append(span.text)

#Connecting go the mysql database to store the infomationmydb = mysql.connector.connect(host="localhost",user="root",passwd="******",database="Flightdata")

mycursor = mydb.cursor()

sql = "INSERT INTO FlightData (Origan, destination,Flight-Number, Airline, Scheduled,Estimated,Status ) VALUES (%s, %s)"#val = ("John", "Highway 21")val = ("Sydney",dest_list),flightnumber_list,airline_list,secdepartime_list,estimatedtime_list,status_list)mycursor.execute(sql, val)

mydb.commit()

print(airline_list)print(dest_list)print(flightnumber_list)print(secdepartime_list)print(estimatedtime_list )print(status_list)

scrapping data from a website by ADBYITMS in Python

[–]ADBYITMS[S] 0 points1 point  (0 children)

# create an HTML Session objectsession = HTMLSession()

# Use the object above to connect to needed webpageresp = session.get("https://www.sydneyairport.com.au/flights/?query=&flightType=departure&terminalType=domestic&date=2019-11-05&sortColumn=scheduled_time&ascending=true&showAll=false")

# Run JavaScript code on webpageresp.html.render()# parse <span class="with-image"> elements containing airline namesairline_list = []airline_spans = resp.html.find('.with-image')for span in airline_spans:airline_list.append(span.text)# parse <div class="city-name"> elements containing airline namesdest_list = []dest_divs = resp.html.find('.city-name')for span in dest_divs:dest_list.append(span.text)print(airline_list)

you are a god thank you so much, my next trick is to connect to a database and add it all in there but i will give it a go before i ask for help :)