Commits

Michele Orrù committed f4a002d

Splitting web application in a separate file

Comments (0)

Files changed (2)

 """
 import logging
 import sys
-import csv
 from optparse import OptionParser
 
-from pattern.en import sentiment
-
 from process import process
-import graph
-
-import flask
-app = flask.Flask(__name__)
-
-@app.route('/graph/js/graph.js')
-def foo():
-    return open('wiki-polarization/js/graph.js').read()
-
-@app.route('/graph/<txtcsv>')
-def plot(txtcsv):
-    """
-    Import the CSV file created with TalkProcessor, and populate a graph where:
-     - each node is identified by a single person.
-     - each link is weighted according to the mean of sentiments between one
-       user and another.
-    The graph is supposed to show people with strong accordance more near than
-    people in opposition.
-    """
-    talk_graph = graph.Graph()
-
-    with open(txtcsv) as txt:
-        csv_reader = csv.DictReader(txt,
-                                    fieldnames='author,target,msg'.split(','),
-                                    delimiter='#')
-
-        for line in csv_reader:
-            author = line['author']
-            target = line['target']
-            msg = line['msg']
-
-            if not target:
-                logging.debug(('User %s reported this message referring to '
-                               'nobody: %s') % (author, msg))
-                continue
-            else:
-                # Add a new node using the Edge class declared above
-                talk_graph.add_edge(author, target,
-                                    weight=sentiment(msg)[0],
-                                    base=graph.Edge, type='is-related-to')
-
-    return graph.render(talk_graph, frames=1, ipf=0)
+from webapp import app as webapp
 
 
 if __name__ == '__main__':
         # process!
         process(xmlfile, outcsv)
     else:
-        if len(files) != 1:
-            optparser.error('Invalid file arguments. Use --help option for'
-                            'details')
-        else:
-            outgraph, = files
-        # plot!
-        #plot(outgraph)
-        app.run()
+        # launch web applciation!
+        webapp.run()
+"""
+Set up a simple web application to display with an intuitive graph Wikipedia
+interaction betweeen users.
+"""
+
+import csv
+
+import flask
+from pattern.en import sentiment
+
+from process import process
+import graph
+
+
+# start flask app
+app = flask.Flask(__name__)
+
+
+@app.route('/graph/js/graph.js')
+def foo():
+    return open('wiki-polarization/js/graph.js').read()
+
+@app.route('/graph/<txtcsv>')
+def plot(txtcsv='foo.csv'):
+    """
+    Import the CSV file created with TalkProcessor, and populate a graph where:
+     - each node is identified by a single person.
+     - each link is weighted according to the mean of sentiments between one
+       user and another.
+    The graph is supposed to show people with strong accordance more near than
+    people in opposition.
+    """
+    talk_graph = graph.Graph()
+
+    with open(txtcsv) as txt:
+        csv_reader = csv.DictReader(txt,
+                                    fieldnames='author,target,msg'.split(','),
+                                    delimiter='#')
+
+        for line in csv_reader:
+            author = line['author']
+            target = line['target']
+            msg = line['msg']
+
+            if not target:
+                logging.debug(('User %s reported this message referring to '
+                               'nobody: %s') % (author, msg))
+                continue
+            else:
+                # Add a new node using the Edge class declared above
+                talk_graph.add_edge(author, target,
+                                    weight=sentiment(msg)[0],
+                                    base=graph.Edge, type='is-related-to')
+
+    return graph.render(talk_graph, frames=1, ipf=0)
+
+