| Revision 82,
777 bytes
checked in by nigel, 5 years ago
(diff) |
|
Added DB read commands
|
| Line | |
|---|
| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | DRUPAL_URL='http://192.168.1.50/~nigel/drupal47/xmlrpc.php' |
|---|
| 4 | DRUPAL_USERNAME='nigel' |
|---|
| 5 | DRUPAL_PASSWORD='trustno1' |
|---|
| 6 | DRUPAL_STATIONID='6551' |
|---|
| 7 | |
|---|
| 8 | DB_NAME='open2300' |
|---|
| 9 | DB_USERNAME='open2300' |
|---|
| 10 | DB_PASSWORD='open2300' |
|---|
| 11 | DB_HOST='localhost' |
|---|
| 12 | |
|---|
| 13 | import xmlrpclib |
|---|
| 14 | import MySQLdb |
|---|
| 15 | |
|---|
| 16 | s = xmlrpclib.ServerProxy(DRUPAL_URL) |
|---|
| 17 | |
|---|
| 18 | conn = MySQLdb.connect(host=DB_HOST, user=DB_USERNAME, passwd=DB_PASSWORD, db=DB_NAME) |
|---|
| 19 | cur = conn.cursor(MySQLdb.cursors.DictCursor) |
|---|
| 20 | # Select the newest record |
|---|
| 21 | if cur.execute("SELECT * FROM `weather` ORDER BY `timestamp` DESC LIMIT 1;") == 1: |
|---|
| 22 | row = cur.fetchone() |
|---|
| 23 | # convert all elements to strings |
|---|
| 24 | for i in row: |
|---|
| 25 | row[i] = str(row[i]) |
|---|
| 26 | |
|---|
| 27 | print s.openweather.addEntry(DRUPAL_STATIONID, DRUPAL_USERNAME, DRUPAL_PASSWORD, row) |
|---|
| 28 | |
|---|
| 29 | cur.close() |
|---|
| 30 | conn.close() |
|---|
| 31 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.