Zum Inhalt springen

Python Scripte

Aus Computech CMS Wiki

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 = "zeber.li",
		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()