Changeset 82 for openweather


Ignore:
Timestamp:
04/01/07 03:04:57 (5 years ago)
Author:
nigel
Message:

Added DB read commands

File:
1 edited

Legend:

Unmodified
Added
Removed
  • openweather/update.py

    r80 r82  
    11#!/usr/bin/env python 
    22 
    3 DRUPAL_URL='http://localhost/~nigel/drupal47/xmlrpc.php' 
     3DRUPAL_URL='http://192.168.1.50/~nigel/drupal47/xmlrpc.php' 
    44DRUPAL_USERNAME='nigel' 
    55DRUPAL_PASSWORD='trustno1' 
     
    1212 
    1313import xmlrpclib 
     14import MySQLdb 
    1415 
    1516s = xmlrpclib.ServerProxy(DRUPAL_URL) 
    1617 
    17 print s.openweather.addEntry(DRUPAL_STATIONID, DRUPAL_USERNAME, DRUPAL_PASSWORD) 
     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]) 
    1826 
     27        print s.openweather.addEntry(DRUPAL_STATIONID, DRUPAL_USERNAME, DRUPAL_PASSWORD, row) 
     28 
     29cur.close() 
     30conn.close() 
     31 
Note: See TracChangeset for help on using the changeset viewer.