Python Scripte: Unterschied zwischen den Versionen
Erscheinungsbild
Keine Bearbeitungszusammenfassung |
|||
| Zeile 7: | Zeile 7: | ||
try: | try: | ||
db = MySQLdb.connect( | |||
host = "194.126.200.54", | host = "194.126.200.54", | ||
user = "zeberlie_raspber", | user = "zeberlie_raspber", | ||
| Zeile 15: | Zeile 15: | ||
except Exception as e: | except Exception as e: | ||
sys.exit('keine verbindung zur Datenbank') | sys.exit('keine verbindung zur Datenbank') | ||
cursor = db.cursor() | cursor = db.cursor() | ||
cursor.execute('INSERT INTO markers (name, address, lat, lng, type) VALUES ("Heldswil","hoehenzelg", " | cursor.execute('INSERT INTO markers (name, address, lat, lng, type) VALUES ("Heldswil","hoehenzelg", "47.143898333","7.792436667","Ballon")') | ||
cursor.execute('SELECT * FROM markers') | cursor.execute('SELECT * FROM markers') | ||
result = cursor.fetchall() | result = cursor.fetchall() | ||
if result: | if result: | ||
for z in result: | for z in result: | ||
Version vom 28. Januar 2014, 17:09 Uhr
MySQL Verbindung
#!/usr/bin/python
import MySQLdb
import sys
#db = MySQLdb.connect("194.126.200.54","zeberlie_raspber","Xe-2UY*7Me?8G","zeberlie_raspberry" )
try:
db = MySQLdb.connect(
host = "194.126.200.54",
user = "zeberlie_raspber",
passwd = "Xe-2UY*7Me?8G",
db = "zeberlie_raspberry"
)
except Exception as e:
sys.exit('keine verbindung zur Datenbank')
cursor = db.cursor()
cursor.execute('INSERT INTO markers (name, address, lat, lng, type) VALUES ("Heldswil","hoehenzelg", "47.143898333","7.792436667","Ballon")')
cursor.execute('SELECT * FROM markers')
result = cursor.fetchall()
if result:
for z in result:
print z[1]+': '+z[2]
Pushover mit Python
import httplib, urllib
# Application specific variables
application_token = "aDhLdifpd6aTkuuPjLAjYS19hYtQPU"
user_token = "uqsV4ZLmM8q7FjgtbjzyXrUZHheLdx"
# Message specific variables
title = "Position"
message = "Wir sind in"
url = "http://michaelhleonard.com/blog"
# To remove any of these fields you will need to remove them
# from the conn.request() below
# Start your connection with the Pushover API server
conn = httplib.HTTPSConnection("api.pushover.net:443")
# Send a POST request in urlencoded json
conn.request("POST", "/1/messages.json",
urllib.urlencode({
"token": application_token,
"user": user_token,
"title": title,
"message": message,
"url": url,
}), { "Content-type": "application/x-www-form-urlencoded" })
# Listen for any error messages or other responses
conn.getresponse()