create account

Teaching myself Python Day 3 by mytechtrail

View this thread on: hive.blogpeakd.comecency.com
· @mytechtrail ·
$0.12
Teaching myself Python Day 3
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](https://files.steempeak.com/file/steempeak/mytechtrail/HEtZWklh-pylearn-day3.png)

```python
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()

```
👍  , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authormytechtrail
permlinkteaching-myself-python-day-3
categoryulog
json_metadata{"app":"steempeak/1.17.0","format":"markdown","tags":["ulog","marlians","palnet","python","stem","ctp"],"image":["https://files.steempeak.com/file/steempeak/mytechtrail/HEtZWklh-pylearn-day3.png"]}
created2019-09-24 20:28:00
last_update2019-09-24 20:28:00
depth0
children4
last_payout2019-10-01 20:28:00
cashout_time1969-12-31 23:59:59
total_payout_value0.063 HBD
curator_payout_value0.061 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length961
author_reputation18,997,364,795,810
root_title"Teaching myself Python Day 3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,907,619
net_rshares587,875,171,097
author_curate_reward""
vote details (24)
@mytechtrail ·
@trufflepig
properties (22)
authormytechtrail
permlinkre-mytechtrail-pyi1b6
categoryulog
json_metadata{"tags":["ulog"],"app":"steempeak/1.17.1"}
created2019-09-27 16:48:00
last_update2019-09-27 16:48:00
depth1
children0
last_payout2019-10-04 16:48:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length11
author_reputation18,997,364,795,810
root_title"Teaching myself Python Day 3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id91,004,790
net_rshares0
@s77assistant ·
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](https://steemconnect.com/sign/delegateVestingShares?delegatee=s77assistant&vesting_shares=50%20SP), [100SP](https://steemconnect.com/sign/delegateVestingShares?delegatee=s77assistant&vesting_shares=100%20SP), [250SP](https://steemconnect.com/sign/delegateVestingShares?delegatee=s77assistant&vesting_shares=250%20SP), [500SP](https://steemconnect.com/sign/delegateVestingShares?delegatee=s77assistant&vesting_shares=500%20SP), [1,000SP](https://steemconnect.com/sign/delegateVestingShares?delegatee=s77assistant&vesting_shares=1000%20SP), [5,000SP](https://steemconnect.com/sign/delegateVestingShares?delegatee=s77assistant&vesting_shares=5000%20SP), [Custom Amount](https://steembottracker.com/delegation.html?delegatee=s77assistant)
Make sure you have at least 15 SP left on your account.

___

[Visit](https://steempeak.com/@s77assistant/golden-deals-report-26-09-2019) s77assistant's daily report to stay informed about any news

___

s77assistant now supports his first game.
[![image.png](https://files.steempeak.com/file/steempeak/dragonblades/sWoeSCBw-image.png)](https://steemit.com/games/@s77assistant/lucky-numbers-report-2)

___

**[Golden Deals!!!](https://steemit.com/palnet/@s77assistant/golden-deals-report-26-09-2019)** Win amazing rewards including Legendary SteemMonster Cards, SBI Shares and STEEM
[![image.png](https://files.steempeak.com/file/steempeak/dragonblades/94TML0SA-image.png)](https://steemit.com/palnet/@s77assistant/golden-deals-report-26-09-2019)
properties (22)
authors77assistant
permlink6exipfsiqpl
categoryulog
json_metadata""
created2019-09-26 12:05:09
last_update2019-09-26 12:05:09
depth1
children0
last_payout2019-10-03 12:05:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,345
author_reputation12,293,901,128,654
root_title"Teaching myself Python Day 3"
beneficiaries
0.
accountdragonblades
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,962,279
net_rshares0
@yapcat · (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 ):

<b>installsteem.sh0</b>

```
#!/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


<b>pythoncat.py</b>  (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
<b>customcenter.py</b>

```
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](https://cdn.steemitimages.com/DQmZFstUi5d4V7pfV4i2wStee1t9nMLxLAHDi7TLmCkX6HQ/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
👍  
properties (23)
authoryapcat
permlinkpz11oj
categoryulog
json_metadata{"tags":["post"],"links":["https://steemit.com/steem/@xeroc/steem-transaction-signing-in-a-nutshell","http://localhost/api_tyr/dc_v1.php","https://alleycat.be/api_tyr/dc_v1.php"],"app":"steemit/0.1","users":["gmdatacenter","goldmanmorgan"],"image":["https://cdn.steemitimages.com/DQmZFstUi5d4V7pfV4i2wStee1t9nMLxLAHDi7TLmCkX6HQ/animated-have-a-nice-day-image-0008.gif"]}
created2019-10-07 23:09:57
last_update2019-10-07 23:21:18
depth1
children1
last_payout2019-10-14 23:09:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,608
author_reputation-721,279,119,965
root_title"Teaching myself Python Day 3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id91,331,259
net_rshares24,986,177,727
author_curate_reward""
vote details (1)
@mytechtrail ·
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.
properties (22)
authormytechtrail
permlinkre-yapcat-pz1313
categoryulog
json_metadata{"tags":["ulog"],"app":"steempeak/1.17.1"}
created2019-10-07 23:39:42
last_update2019-10-07 23:39:42
depth2
children0
last_payout2019-10-14 23:39:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length172
author_reputation18,997,364,795,810
root_title"Teaching myself Python Day 3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id91,331,713
net_rshares0