from flask import Flask

import boto3
from boto3.dynamodb.conditions import Key, Attr
import json
from textblob import TextBlob
import preprocessor as p

app = Flask(__name__)


dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('fuck')
print(table)


with open('../zip2fips.json') as data_file:
    zip2fips = json.load(data_file)

fips = set(zip2fips.values())

RESULT = {'ID': 825535001265655808,
          'fips': 34035,
          'hashtags': [],
          'polarity': '0.5',
          'subjectivity': '0.5',
          'text': "@ScottPresler Most people would be ok with that, but that's not what "
                  "happened, is it? Fools didn't think it thru all the way, or set it "
                  'up.',
          'timestamp': 1485657856000,
          'zipcode': 8873}

@app.route("/")
def hello():
    resp = table.scan(FilterExpression=Attr("fips").exists())
    sorted_by_fips = {}
    for item in resp['Items']:
        concat = " ".join(item['tweet'])
        testimonal = TextBlob(concat)
        polarity = (testimonal.sentiment.polarity)

        sorted_by_fips[str(item['fips'])] = polarity

    return json.dumps(sorted_by_fips)



if __name__ == "__main__":
    app.run()
@@ -125,56 +125,102 @@
 lob%0A
-import preprocessor as p%0A%0Aapp = Flask(__name__)%0A
+from flask_cors import CORS%0A%0Aapp = Flask(__name__)%0ACORS(app, resources=r'*', crossdomain=True)
 %0A%0Ady
@@ -417,425 +417,8 @@
 ))%0A%0A
-RESULT = %7B'ID': 825535001265655808,%0A          'fips': 34035,%0A          'hashtags': %5B%5D,%0A          'polarity': '0.5',%0A          'subjectivity': '0.5',%0A          'text': %22@ScottPresler Most people would be ok with that, but that's not what %22%0A                  %22happened, is it? Fools didn't think it thru all the way, or set it %22%0A                  'up.',%0A          'timestamp': 1485657856000,%0A          'zipcode': 8873%7D%0A
 %0A@ap
@@ -529,16 +529,49 @@
 ps = %7B%7D%0A
+    sorted_by_fips%5B'items'%5D = %5B%5D%0A
     for 
@@ -747,16 +747,38 @@
 by_fips%5B
+'items'%5D.append(%7B'id':
 str(item
@@ -786,19 +786,25 @@
 'fips'%5D)
-%5D =
+, 'rate':
  polarit
@@ -804,16 +804,18 @@
 polarity
+%7D)
 %0A%0A    re
@@ -847,18 +847,16 @@
 _fips)%0A%0A
-%0A%0A
 if __nam

proper output for react