This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import psycopg2 | |
| import sqlalchemy | |
| from decouple import config | |
| #AWS_DATABASE_URL is 'postgres://username:password@database-instance-name.randomchars.us-east-2.rds.amazonaws.com:5432/databaseName | |
| host = config('AWS_DATABASE_URL') | |
| db = sqlalchemy.create_engine(host) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pickle | |
| filename = "saved_thing" | |
| infile = open(filename, "rb") | |
| thing = pickle.load(infile) | |
| infile.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pickle | |
| filename = "saved_thing" | |
| outfile = open(filename,'wb') | |
| pickle.dump(thing, outfile) | |
| outfile.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def execute_async_event_loop(min_song, max_song, song_urls): | |
| """ | |
| This function does something analogous to compiling the get_data_asynchronously function, | |
| Then it executes loop. | |
| 1. Call the get_data_function | |
| 2. Get the event_loop | |
| 3. Run the tasks (Much easier to understand in python 3.7, "ensure_future" was changed to "create_task") | |
| 4. Edge_list and top_interactions will be passed to the next functions | |
| """ | |
| future = asyncio.create_task( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from decouple import config | |
| import json | |
| import requests | |
| import sys | |
| import asyncio | |
| from concurrent.futures import ThreadPoolExecutor | |
| import nest_asyncio | |
| nest_asyncio.apply() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async def get_data_asynchronous(min_song, max_song, song_urls): | |
| """ | |
| 1. Establish an executor and number of workers | |
| 2. Establish the session | |
| 3. Establish the event loop | |
| 4. Create the task by list comprehensions | |
| 5. Gather tasks. | |
| """ | |
| with ThreadPoolExecutor(max_workers=40) as executor: | |
| with requests.Session() as session: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def request_song_info(session, song_num, song_urls): | |
| base_url = "https://api.genius.com/songs/" + str(song_num) | |
| headers = {"Authorization": "Bearer " + CLIENT_ACCESS_TOKEN} | |
| response = requests.get(base_url, headers=headers) | |
| try: | |
| if response.json()["meta"]["status"] == 200: | |
| song_urls.append( | |
| ( | |
| song_num, | |
| response.json()["response"]["song"]["title"], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!--make the html element to contain the chart.--> | |
| <canvas id="line-chart" width="3" height="1"></canvas> | |
| {% block javascript %} | |
| <script> | |
| // load the objects like you would with a normal jinja template i.e. {{ object }}, but add | tojson | |
| // pass it into the parse function | |
| labels = JSON.parse({{ labels | tojson }}) | |
| data = JSON.parse({{ data | tojson }}) | |
| new Chart(document.getElementById("line-chart"),{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #The important imports for this tutorial | |
| from flask import Flask, render_template, json | |
| #Skiping a whole lot of the file to get to the useful parts. | |
| """Focusing on just this route that display a linechart for the sentiment of a topic over time.""" | |
| @app.route('/line', methods =["GET"]) | |
| def line_chart(): | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| model = create_model(gp_result.x[0],gp_result.x[1],gp_result.x[2],gp_result.x[3],gp_result.x[4],gp_result.x[5]) | |
| model.fit(X_train,y_train, epochs=3) | |
| model.evaluate(X_test,y_test) |