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
| # Portfolio preprocessing | |
| values = [] | |
| # Iterate the dataframe | |
| for index, row in portfolio.iterrows(): | |
| # Set the default value | |
| new_value = [0,0,0,0] | |
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 matplotlib.colors import ListedColormap | |
| from tqdm import tqdm | |
| import matplotlib.patches as mpatches | |
| import matplotlib.pyplot as plt | |
| import pandasql as pdsql | |
| import seaborn as sns | |
| import pandas as pd | |
| import numpy as np | |
| import math |
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 telegram.ext import Updater, CommandHandler | |
| import pandas as pd | |
| import logging | |
| # Set the logging function to print the error message whenever it happens | |
| logging.basicConfig(level=logging.DEBUG, format='%(levelname)s - %(message)s') | |
| logger = logging.getLogger() | |
| logger.setLevel(logging.ERROR) |
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 main(): | |
| # Initiate the bot and add command handler | |
| updater = Updater('YOUR_BOT_TOKEN', use_context=True) | |
| updater.dispatcher.add_handler(CommandHandler('word', send_word)) | |
| # Run the bot | |
| updater.start_polling() | |
| updater.idle() |
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 send_word(update, context): | |
| # Read the dataset and pick a random word | |
| dictionary = pd.read_csv('dictionary.csv') | |
| word = dictionary['word'].sample(1).values[0] | |
| # Get the user chat_id for sending back the message | |
| chat_id = update.message.chat_id | |
| # Send the word and the audio |
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 google.cloud import texttospeech | |
| from bs4 import BeautifulSoup | |
| import pandas as pd | |
| import requests | |
| import re | |
| def get_hangeul(): |
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 create_audio(text, language='ko-KR'): | |
| # Instantiates a client | |
| client = texttospeech.TextToSpeechClient() | |
| # Set the text input to be synthesized | |
| synthesis_input = texttospeech.types.SynthesisInput(text=text) | |
| # Build the voice request, select the language code ("en-US") and the ssml | |
| # voice gender ("neutral") |
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 get_hangeul(): | |
| # Scrape the website and get list of titles | |
| url = 'https://www.bbc.com/korean/popular/read' | |
| page = requests.get(url) | |
| soup = BeautifulSoup(page.content, 'html.parser') | |
| titles = soup.findAll('span', | |
| {'class': 'most-popular-list-item__headline'}) | |
| # Iterate through titles -> remove punctuation -> append to the list |
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 google.cloud import texttospeech | |
| from bs4 import BeautifulSoup | |
| import pandas as pd | |
| import requests | |
| import re |
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 os | |
| import io | |
| import sys | |
| import subprocess | |
| import tesserocr | |
| from pyspark.sql import SparkSession | |
| # Initiate spark session | |
| spark = SparkSession.builder \ |