Teaching myself Python Day 3

avatar

Now the code queries a database and displays a value when pressing the button. Need to learn how to better arrange the button and text output in the window.

pylearnday3.png

import MySQLdb
from tkinter import *
from tkinter.ttk import *

window =Tk()
window.title("Pylearn Day 3")
window.geometry('1024x768')
lbl = Label(window, text="hello", font=("Arial Bold", 50))
lbl.grid(column=100, row=10)
def clicked2():
    db = MySQLdb.connect("192.168.1.200", "pidata", "Rasp!data99", "home_data")
    cursor = db.cursor()
    sqlcmd = "select max(temp) from temperatures where tempTime like '2019-09-24%';"
    cursor.execute(sqlcmd)
    row = cursor.fetchone()
    lbl.configure(text= "Max Temp " + str(row[0]), font=("Arial Bold", 14))
    db.close()
button_2 = Button(window, text="Click Me!", command=clicked2)
button_2.grid(column=2, row=9)

window.mainloop()



0
0
0.000
4 comments
avatar

Hello fellow @mytechtrail

Your post was upvoted with 38.31% ($0.0123) because you are an awesome member of s77assistant group.

You have earn a total of $0.7732 so far. keep it up.
Together we can achieve our goal and push STEEM to the moon.

You can increase your upvote value by increasing your collected points with one of the following ways:

  1. Delegating more SP will generate more points per day,
  2. Inviting other steemians to join our group with !invite(@membername) command,
  3. Transfering Steem/SBD

Don't forget to use EnhancedSBI functionality every day and get 3 SBI shares for every 2 STEEM you send with 2for3 memo.


At the current time my full vote worth $0.032 but with your help this can change.
Delegating power will increase my vote worth and your reward.
50SP, 100SP, 250SP, 500SP, 1,000SP, 5,000SP, Custom Amount
Make sure you have at least 15 SP left on your account.


Visit s77assistant's daily report to stay informed about any news


s77assistant now supports his first game.
image.png


Golden Deals!!! Win amazing rewards including Legendary SteemMonster Cards, SBI Shares and STEEM
image.png

0
0
0.000
avatar
(Edited)

hmm ... i'm not the python guy but so far when dealing with steem(it) it seems pretty much inevitable ... i havent found any php lib and if its not for parsing w. condenser python seems about the only option other than 'manually' signing ( = lol )

->

https://steemit.com/steem/@xeroc/steem-transaction-signing-in-a-nutshell

(in a nutshell as the dude so eloquently states)

i dont know what OS tickles your fancy but im prone to l00nix (mint usually, regardless of the front desktop, that depends on the hardware, i find cinnamon the most pleasing but not really fit for my celeron-machines ...)

so

(not sure if you need this, im sure you didnt ask for it but if you wanna do steem it might help - i find the documentation severely lacking and even the how-to installit on linux didnt work for me as is , so ):

installsteem.sh0

#!/bin/bash
#######################################
sudo apt install -y git
git clone https://github.com/steemit/steem-python.git
sudo apt install -y python3-dev
cd steem-python
sudo apt install -y python3-setuptools
sudo apt install -y libssl-dev
sudo python3 setup.py install

did it last time

then you can use steempy from the cli

steempy

or

steempy --help

...the usual , for all wallet stuff and voting (following too i think and some other stuff , and

pythoncat.py (more like a copy paste adapted from some thing i found somewhere)

from steem import Steem
from steem.transactionbuilder import TransactionBuilder
from steembase import operations

import time, random, os

def buy_upvote(author,upvote_bot, amount, permlink):
    transfers =[{
        'from': author,
        'to': upvote_bot,
        'amount': '{0:.3f} SBD'.format(amount),
        'memo': 'https://steemit.com/@{}/{}'.format(author, permlink)
    }]
    tb = TransactionBuilder()
    operation = [operations.Transfer(**x) for x in transfers]
    tb.appendOps(operation)
    tb.appendSigner(author, 'active')
    tb.sign()

    try:
        tx = tb.broadcast()
        print ("Buying vote succes")
    except Exception as error:
        print(repr(error))



def submit_post(title, tags, body, author):
    steemPostingKey = os.environ.get('steemPostingKey')
    steem = Steem(wif=steemPostingKey)

    permlink_title = ''.join(e for e in title if e.isalnum()).lower()
    permlink = "{}-%s%s".format(permlink_title) % (time.strftime("%Y%m%d%H%M%S"), random.randrange(0,9999,1))

    try:
        steem.post(title, body, author, permlink, None, None, None, None, tags, None, False)
        print ("Submitted post")
    except Exception as error:
        print(repr(error))

    return permlink


def run():
    author = 'ubakdhfsdkljhfsdklsti'
    upvote_bot = 'minnowbooster'
    amount = 0.05

    post = [line.rstrip('\n') for line in open('postbodytext')]
    title  = post[0]
    tags = post[1]
    author = post[2]
    body = '\n'.join(post[3:])

    permlink = submit_post(title, tags, body, author)


if __name__ == '__main__':
    run()

if found that somewhere else, just mark out the buy an upvote bit and put the postbody in a flatfile (however you want that, typed or pre-generated) and that's good to go and someone pointed me into the direction of custom json this week (which is actually where the real power resides ... and all the bru-ha on communities and smt's is probably nothing more than a 'for the masses' interface to do what was there all along .. musing and steemmonsters , steemstem, drugwars and probably a zound more have been doing that a long time
customcenter.py

from steem import Steem
from steem.transactionbuilder import TransactionBuilder
from steembase import operations
s = Steem(nodes=["https://api.steemit.com"],
          keys=["INSERTTHATPOSTINGKEYHERE"])
account = "INSERTYOURACCOUNTNAMEHERE"
apythonvariable = "i dont really know howapythonvariable works and what it looks like"
#post = [line.rstrip('\n') for line in open('ascithing')]
ops = [
    operations.CustomJson(**{
        "from": account,
        "id": "dndchar",
        "json": [ 'my char',
            {
                "name": "Von Trappiël",
                "race": "high elf",
                "alignment": "chaotic-good",
                "STATS": "STR:12,DEX:18,CON:10,INT:16:WIS:14,CHA:16",
                "ETCETERA": "i suppose you can use more brackets im not the json expert",
                "ETC2": "and stuff",
                "args": apythonvariable
            }
        ],
        "required_auths": [],
        "required_posting_auths": ["INSERTYOURACCOUNTNAMEHERE"],
    }),
]
tb = TransactionBuilder()
tb.appendOps(ops)
tb.appendSigner(account, "posting")
tb.sign()
tb.broadcast()

(to read a file into var you just unmark the #post bit , im sure you know plenty to read the code) i really dont know jack about python lol i never needed it and its only by necessity for lack of php-signing lib which i cant find anywhere (or unix lib for that matter so the heavy layer of python seems unavoidable)

should both work if you imported an account keys into steempy with

steempy importaccount (i think)

the flatfile for posting has title at line 0, tags at line 1 etc ... but since you know base python (probably more than me you can read that
im starting to assume like the elder devs do here lol

anyway ... maybe it helps with the hobby ...

since i just though of it ... i just thought ...

if you got any working scripts that do anything steemrelated sure don't mind you leave them in a reply to the only post i have on my feed here (but just as good if you dont, its just fyi)

second one has the posting key in it 'naked which i dont really like but its not an actual disaster either ... i hope i didnt leave any of mine in ;-

:: funny lulz like custom ascii logos :

http://localhost/api_tyr/dc_v1.php

euhm yagh make that

https://alleycat.be/api_tyr/dc_v1.php (stands for datacenter @gmdatacenter, not disconnection heh)

v2 is testing the ways to pack all @goldmanmorgan wallets into one chunk but offline when im not working on it (its just some bedroom leftover pc, not meant for hi traffic)

or you could build steemmonsters, i guess, if you had UltiMatt drive & money :D

animated-have-a-nice-day-image-0008.gif

i always find an example to mess with is worth 20 pages of theory and seven courses by some elite dude who thinks everyone speaks school-kid ... but im just a hobbyist ofcourse ;-)))))

right ... im gonna try and remember what i was doing ttyl cu around

0
0
0.000
avatar

Thanks, I will try and leave comment when I get some working Steem related Python code.

I agree that looking at some working code is the way I am able to learn new things.

0
0
0.000