source: openweather/update.py @ 82

Revision 82, 777 bytes checked in by nigel, 5 years ago (diff)

Added DB read commands

Line 
1#!/usr/bin/env python
2
3DRUPAL_URL='http://192.168.1.50/~nigel/drupal47/xmlrpc.php'
4DRUPAL_USERNAME='nigel'
5DRUPAL_PASSWORD='trustno1'
6DRUPAL_STATIONID='6551'
7
8DB_NAME='open2300'
9DB_USERNAME='open2300'
10DB_PASSWORD='open2300'
11DB_HOST='localhost'
12
13import xmlrpclib
14import MySQLdb
15
16s = xmlrpclib.ServerProxy(DRUPAL_URL)
17
18conn = MySQLdb.connect(host=DB_HOST, user=DB_USERNAME, passwd=DB_PASSWORD, db=DB_NAME)
19cur = conn.cursor(MySQLdb.cursors.DictCursor)
20# Select the newest record
21if 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
29cur.close()
30conn.close()
31
Note: See TracBrowser for help on using the repository browser.