Beginning of twitter interaction in service alerts component
Beginning of twitter interaction in service alerts component

--- a/aws/busuidb.sh
+++ b/aws/busuidb.sh
@@ -11,7 +11,4 @@
 #psql -d transitdata -c "GRANT SELECT,INSERT ON	TABLE myway_observations,myway_routes,myway_stops,myway_timingdeltas TO transitdata;"
 #psql -d transitdata -c	"GRANT SELECT,INSERT,UPDATE ON TABLE myway_routes,myway_stops TO transitdata;"
 ##psql -d transitdata -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO transitdata;"
-## INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type")
-##SELECT '', 'public', 'shapes', 'shape_pt', ST_CoordDim(shape_pt), ST_SRID(shape_pt), GeometryType(shape_pt)
-##FROM shapes LIMIT 1;
 php /var/www/updatedb.php

--- a/include/db/trip-dao.inc.php
+++ b/include/db/trip-dao.inc.php
@@ -33,31 +33,17 @@
     }
     return $query->fetch(PDO :: FETCH_ASSOC);
 }
-function getTripStops($tripID) {
+
+function getTripShape($tripID) {
+    // todo, use shapes table if shape_id specified
     global $conn;
-    $query = "SELECT stop_id, stop_name, ST_AsKML(position) as positionkml,
+    $query = "SELECT ST_AsKML(ST_MakeLine(geometry(a.position))) as the_route
+FROM (SELECT position,
 	stop_sequence, trips.trip_id
 FROM stop_times
 join trips on trips.trip_id = stop_times.trip_id
 join stops on stops.stop_id = stop_times.stop_id
-WHERE trips.trip_id = :tripID ORDER BY stop_sequence";
-    debug($query, "database");
-    $query = $conn->prepare($query);
-    $query->bindParam(":tripID", $tripID);
-    $query->execute();
-    if (!$query) {
-        databaseError($conn->errorInfo());
-        return Array();
-    }
-    return $query->fetchColumn(0);
-}
-function getTripShape($tripID) {
-    // todo, use shapes table if shape_id specified
-    global $conn;
-    $query = "SELECT ST_AsKML(ST_MakeLine(geometry(a.shape_pt))) as the_route
-FROM (SELECT shapes.shape_id,shape_pt from shapes
-inner join trips on shapes.shape_id = trips.shape_id
-WHERE trips.trip_id = :tripID ORDER BY shape_pt_sequence) as a group by a.shape_id";
+WHERE trips.trip_id = :tripID ORDER BY stop_sequence) as a group by a.trip_id";
     debug($query, "database");
     $query = $conn->prepare($query);
     $query->bindParam(":tripID", $tripID);

--- a/servicealerts/importer.py
+++ b/servicealerts/importer.py
@@ -1,5 +1,3 @@
-#dependencies http://code.google.com/p/python-twitter/
-
 # info
 # http://stackoverflow.com/questions/4206882/named-entity-recognition-with-preset-list-of-names-for-python-php/4207128#4207128
 # http://alias-i.com/lingpipe/demos/tutorial/ne/read-me.html approximate dist
@@ -14,9 +12,13 @@
 # source: https://gist.github.com/322906/90dea659c04570757cccf0ce1e6d26c9d06f9283
 import nltk
 import twitter
+import tweepy
 import psycopg2
+from iniparse import INIConfig
+
 def insert_service_alert_sitewide(heading, message, url):
-        
+        print "NaN"
+
 def insert_service_alert_for_street(streets, heading, message, url):
     	conn_string = "host='localhost' dbname='energymapper' user='postgres' password='snmc'"
 	# print the connection string we will use to connect
@@ -29,30 +31,22 @@
 		cursor = conn.cursor()
 
 		# execute our Query
-		cursor.execute("select max(value), extract(dow from max(time)) as dow, \
-extract(year from max(time))::text || lpad(extract(month from max(time))::text,2,'0') \
-|| lpad(extract(month from max(time))::text,2,'0') as yearmonthweek, to_char(max(time),'J') \
-from environmentdata_values where \"dataSourceID\"='NSWAEMODemand' \
-group by extract(dow from time), extract(year from time),  extract(week from time) \
-order by  extract(year from time),  extract(week from time), extract(dow from time)")
+		cursor.execute("")
 
 		# retrieve the records from the database
 		records = cursor.fetchall()
 
   	  	for record in records:
 			ys.append(record[0])
-# >>> cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)", (42, 'bar'))
-#>>> cur.statusmessage
-#'INSERT 0 1'
+                # >>> cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)", (42, 'bar'))
+                #>>> cur.statusmessage
+                #'INSERT 0 1'
 	except:
 		# Get the most recent exception
 		exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
 		# Exit the script and print an error telling what happened.
 		sys.exit("Database connection failed!\n ->%s" % (exceptionValue))
 		
-def get_tweets(user):
-    tapi = twitter.Api()
-    return tapi.GetUserTimeline(user)
 
 def extract_entity_names(t):
     entity_names = []
@@ -85,4 +79,16 @@
 
     # Print unique entity names
     print set(entity_names)
+cfg = INIConfig(open('/tmp/aws.ini'))
 
+auth = tweepy.OAuthHandler(cfg.api_keys.twitter_consumer_key, cfg.api_keys.twitter_consumer_secret)
+auth.set_access_token(cfg.api_keys.twitter_access_token, cfg.api_keys.twitter_access_token_secret)
+
+api = tweepy.API(auth)
+
+# If the authentication was successful, you should
+# see the name of the account print out
+print api.me().name
+# https://github.com/tweepy/tweepy/blob/master/tweepy/api.py
+print api.user_timeline(screen_name="ACTPol_Traffic")
+print api.update_status(status="test")

--- a/servicealerts/index.php
+++ b/servicealerts/index.php
@@ -2,17 +2,12 @@
 include ('../include/common.inc.php');
 
 include_header("Service Alerts", "index");
-echo '<ul data-role="listview" data-theme="e" data-groupingtheme="e">';
-	
  if ($_SESSION['authed'] == true) {
- 	echo'	<li><a href="servicealert_editor.php"><h3>servicealert_editor</h3>
-		<p>servicealert_editor</p></a></li>';
-          }
- 	echo'	<li><a href="servicealert_viewer.php"><h3>Service Alert Viewer</h3>
-		<p>Browse current network alerts</p></a></li>';
-          
-           echo'  </ul>';
-
+ 	echo '<ul data-role="listview" data-theme="e" data-groupingtheme="e">
+		<li><a href="servicealert_editor.php"><h3>servicealert_editor</h3>
+		<p>servicealert_editor</p></a></li>
+            </ul>';
+ }
 ?>	    </div>
 <?php
 include_footer()

--- a/servicealerts/servicealert_viewer.php
+++ /dev/null
@@ -1,53 +1,1 @@
-<?php
-/*
- *    Copyright 2010,2011 Alexander Sadleir 
 
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
- */
-include ('../include/common.inc.php');
-include_header("Service Alert Viewer", "serviceAlertViewer");
-/**
- * Currently support:
- * network inform
- * stop remove: route patch, stop remove
- * - stop search
- * street inform: route inform, stop inform
- * - street search
- */
-if (!isset($_REQUEST['view'])) {
-
-?>
-Active and Future Alerts:
-<table>
-    <?php
-    foreach (getFutureAlerts() as $alert) {
-        echo "<tr><td>{$alert['header']}</td><td>" . substr($alert['description'], 0, 999) . '</td><td><a href="?view=' . $alert['id'] . '">View</a></td></tr>';
-    }
-    ?>
-</table>
-<?php
-} else {
-$alert = getServiceAlert($_REQUEST['view']);
-echo "<h1>{$alert['header']}</h1>
-<h2> From ".date("c",$alert['start'])." to ".date("c",$alert['end'])."</h2>
-<small>{$alert['description']}</small><br>
-Source: <A href='{$alert['url']}'>{$alert['url']}</a><br>"; 
-    echo "Informed Entities for ID {$_REQUEST['view']}:";
-    echo '<table>';
-    foreach (getInformedAlerts($_REQUEST['view'], "", "") as $informed) {
-        echo "<tr><td>{$informed['informed_class']}</td><td>{$informed['informed_id']}</td><td>{$informed['informed_action']}" . '</td></tr>';
-    }
-    echo '</table>';
-}
-include_footer();
-?>