Repository navigation
Adding a weather microservice #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| SUBDIRS=commandcenter imagematching questionanswering calendar speechrecognition djinntonic | ||
| SUBDIRS=commandcenter imagematching questionanswering calendar speechrecognition djinntonic weather | ||
|
|
||
| include ../Makefile.common | ||
| include ../Makefile.common |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| San Francisco, CA | ||
| Austin, TX | ||
| San Diego, CA | ||
| Flower Mound, TX | ||
| Tucson, AZ | ||
| New York City, NY | ||
| Lousiville, KY | ||
| Denver, CO | ||
| Atlanta, GA | ||
| Memphis, TN | ||
| Chicago, IL | ||
| Orlando, FL | ||
| New Orleans, LA | ||
| Montgomery, AL | ||
| Juneau, AK | ||
| Phoenix, AZ | ||
| Little Rock, AR | ||
| Sacramento, CA | ||
| Hartford, CT | ||
| Dover, DE | ||
| Washington, DC | ||
| Tallahassee, Florida | ||
| Honolulu, HI | ||
| What's the weather in San Francisco, CA? | ||
| What's the weather in Austin, TX? | ||
| What's the weather in San Diego, CA? | ||
| What's the weather in Flower Mound, TX? | ||
| What's the weather in Tucson, AZ? | ||
| What's the weather in New York City, NY? | ||
| What's the weather in Lousiville, KY? | ||
| What's the weather in Denver, CO? | ||
| What's the weather in Atlanta, GA? | ||
| What's the weather in Memphis, TN? | ||
| What's the weather in Chicago, IL? | ||
| What's the weather in Orlando, FL? | ||
| What's the weather in New Orleans, LA? | ||
| What's the weather in Montgomery, AL? | ||
| What's the weather in Juneau, AK? | ||
| What's the weather in Phoenix, AZ? | ||
| What's the weather in Little Rock, AR? | ||
| What's the weather in Sacramento, CA? | ||
| What's the weather in Hartford, CT? | ||
| What's the weather in Dover, DE? | ||
| What's the weather in Washington, DC? | ||
| What's the weather in Tallahassee, Florida? | ||
| What's the weather like in San Francisco, CA? | ||
| What's the weather like in Austin, TX? | ||
| What's the weather like in San Diego, CA? | ||
| What's the weather like in Flower Mound, TX? | ||
| What's the weather like in Tucson, AZ? | ||
| What's the weather like in New York City, NY? | ||
| What's the weather like in Lousiville, KY? | ||
| What's the weather like in Denver, CO? | ||
| What's the weather like in Atlanta, GA? | ||
| What's the weather like in Memphis, TN? | ||
| What's the weather like in Chicago, IL? | ||
| What's the weather like in Orlando, FL? | ||
| What's the weather like in New Orleans, LA? | ||
| What's the weather like in Montgomery, AL? | ||
| What's the weather like in Juneau, AK? | ||
| What's the weather like in Phoenix, AZ? | ||
| What's the weather like in Little Rock, AR? | ||
| What's the weather like in Sacramento, CA? | ||
| What's the weather like in Hartford, CT? | ||
| What's the weather like in Dover, DE? | ||
| What's the weather like in Washington, DC? | ||
| What's the weather like in Tallahassee, Florida? | ||
| What's the weather in Utah? | ||
| What's the weather in Texas? | ||
| What's the weather in Oklahoma? | ||
| What's the weather in South America? | ||
| What's the weather in Washington? | ||
| What's the weather in New York? | ||
| What's the weather in Kentucky? | ||
| What's the weather in Colorado? | ||
| What's the weather in Georgia? | ||
| What's the weather in Tennessee? | ||
| What's the weather in Illinois? | ||
| What's the weather in Oregon? | ||
| What's the weather in Louisiana? | ||
| What's the weather in Alabama? | ||
| What's the weather in India? | ||
| What's the weather in Arizona? | ||
| What's the weather in Arkansas? | ||
| What's the weather in California? | ||
| What's the weather in Maryland? | ||
| What's the weather in New Mexico? | ||
| What's the weather in Ohio? | ||
| What's the weather in Florida? | ||
| How hot is it in San Francisco, CA? | ||
| How cold is it in Austin, TX? | ||
| How warm is it in San Diego, CA? | ||
| How cool is it in Flower Mound, TX? | ||
| How hot is it in San Francisco? | ||
| How cold is it in Austin? | ||
| How warm is it in California? | ||
| How cool is it in Texas? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| lucidaservice | ||
| lucidatypes |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| all: thrift | ||
|
|
||
| thrift: | ||
| @if [ ! -d "lucidaservice" ]; then \ | ||
| thrift --gen py ../lucidaservice.thrift; \ | ||
| thrift --gen py ../lucidatypes.thrift; \ | ||
| cd gen-py; \ | ||
| mv * ..; \ | ||
| cd ..; \ | ||
| rmdir gen-py; \ | ||
| rm __init__.py; \ | ||
| fi | ||
|
|
||
| clean: | ||
| rm -rf lucidaservice lucidatypes | ||
|
|
||
| start_server: | ||
| cd server; python WeatherServer.py | ||
|
|
||
| start_test: | ||
| cd client; python WeatherClient.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| import sys | ||
| sys.path.append('../') | ||
|
|
||
| from lucidatypes.ttypes import QueryInput, QuerySpec | ||
| from lucidaservice import LucidaService | ||
|
|
||
| from thrift import Thrift | ||
| from thrift.transport import TSocket | ||
| from thrift.transport import TTransport | ||
| from thrift.protocol import TBinaryProtocol | ||
|
|
||
| port = 8088 | ||
|
|
||
| LUCID = "Clinc" | ||
| query_input_data = "What's the weather in Ann Arbor, MI?" | ||
| query_input = QueryInput(type="query", data=[query_input_data]) | ||
| query_spec = QuerySpec(content=[query_input]) | ||
|
|
||
| # Initialize thrift objects | ||
| transport = TTransport.TFramedTransport(TSocket.TSocket("localhost", port)) | ||
| protocol = TBinaryProtocol.TBinaryProtocol(transport) | ||
| client = LucidaService.Client(protocol) | ||
|
|
||
| transport.open() | ||
| print "/////....Connecting to Weather..../////" | ||
| results = client.infer(LUCID, query_spec) | ||
| print "/////Result/////" | ||
| print "%s" % results | ||
| transport.close() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| import sys | ||
| sys.path.append('../') | ||
|
|
||
| from lucidatypes.ttypes import QuerySpec | ||
| from lucidaservice import LucidaService | ||
|
|
||
| from thrift.transport import TSocket | ||
| from thrift.transport import TTransport | ||
| from thrift.protocol import TBinaryProtocol | ||
| from thrift.server import TServer | ||
|
|
||
| import urllib2 | ||
| import json | ||
| import urllib | ||
|
|
||
| port = 8088 | ||
| owm_api_key = "362537b891e6df03a316e82565fe4df3" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ew Magic Numbers, can you move this to a config and put in the README that it needs to be set or something? Should be a "secret" |
||
| wu_api_key = "ff76e8e80c802d46" | ||
|
|
||
| class WeatherHandler(LucidaService.Iface): | ||
| """ | ||
| Do nothing | ||
| Parameters: | ||
| - LUCID: ID of Lucida user | ||
| - spec: spec | ||
| """ | ||
| def create(self, LUCID, spec): | ||
| return | ||
|
|
||
| """ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these docstrings should be inside the function header, check how we do it internally |
||
| Do nothing | ||
| Parameters: | ||
| - LUCID: ID of Lucida user | ||
| - knowledge: knowledge | ||
| """ | ||
| def learn(self, LUCID, knowledge): | ||
| return | ||
|
|
||
| """ | ||
| Determine the weather based off input | ||
| Parameters: | ||
| - LUCID: ID of Lucida user | ||
| - query: query | ||
| """ | ||
| def infer(self, LUCID, query): | ||
| result = "No weather found for %s" % query.content[0].data[0] | ||
| url_location = urllib.quote_plus(query.content[0].data[0]) | ||
|
|
||
| try: | ||
| # weather from Weather Underground | ||
| f = urllib2.urlopen('http://api.wunderground.com/api/%s/conditions/q/%s.json' % (wu_api_key, url_location) ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be a global |
||
| json_string = f.read() | ||
| parsed_json = json.loads(json_string) | ||
| if 'error' not in parsed_json['response'] and 'current_observation' in parsed_json: | ||
| weather = parsed_json['current_observation']['weather'] | ||
| temp = parsed_json['current_observation']['temperature_string'] | ||
| city = parsed_json['current_observation']['display_location']['full'] | ||
| result = "Current weather in %s is %s %s" % (city, weather, temp) | ||
| print "From Weather Underground: %s" % result | ||
| else: | ||
| # weather from Open Weather Map | ||
| f = urllib2.urlopen('http://api.openweathermap.org/data/2.5/weather?q=%s&appid=%s&units=imperial&type=like' % (url_location, owm_api_key)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. global or some config |
||
| json_string = f.read() | ||
| parsed_json = json.loads(json_string) | ||
| if 'weather' in parsed_json and 'main' in parsed_json and 'name' in parsed_json: | ||
| weather = parsed_json['weather'][0]['main'] | ||
| temp = parsed_json['main']['temp'] | ||
| city = parsed_json['name'] | ||
| result = "Current weather in %s is %s, %s F" % (city, weather, temp) | ||
| print "From Open Weather Map: %s" % result | ||
| f.close() | ||
| except urllib2.HTTPError as err: | ||
| if err == "404": | ||
| print result | ||
|
|
||
| return result | ||
|
|
||
| # Set handler to our implementation | ||
| handler = WeatherHandler() | ||
|
|
||
| processor = LucidaService.Processor(handler) | ||
| transport = TSocket.TServerSocket(port=port) | ||
| tfactory = TTransport.TFramedTransportFactory() | ||
| pfactory = TBinaryProtocol.TBinaryProtocolFactory() | ||
|
|
||
| server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) | ||
|
|
||
| print "WE at port %d" % port | ||
| server.serve() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| apiVersion: v1 | ||
| kind: ReplicationController | ||
| metadata: | ||
| labels: | ||
| name: we | ||
| name: we-controller | ||
| spec: | ||
| replicas: 1 | ||
| selector: | ||
| name: we | ||
| template: | ||
| metadata: | ||
| labels: | ||
| name: we | ||
| spec: | ||
| containers: | ||
| - image: claritylab/lucida:v2.2 | ||
| command: ['/bin/sh', '-c'] | ||
| args: ['cd $LUCIDAROOT/weather/server/ && python WeatherServer.py'] | ||
| name: we | ||
| ports: | ||
| - containerPort: 8088 | ||
| name: thrift |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: we | ||
| labels: | ||
| name: we | ||
| spec: | ||
| type: ClusterIP | ||
| ports: | ||
| - port: 8088 | ||
| targetPort: 8088 | ||
| protocol: TCP | ||
| selector: | ||
| name: we |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we really need to rethink how all the ports are set, it's super messy to have them nested deep into the code. then you need to worry about setting them correctly within the CMD center as well