daily log 11.16.20
TIL:
table = soup.find_all('table')
df = pd.read_html(str(table))[0]
pandas and beautiful soup tables Compiler vs Interpreter
Interpreter translates program line by line
Compiler translates program all in one batch
CTCI
BETTER ATTEMPT
As a human computer, I will:
- look at the current letter.
- Take note of this current letter as STORED_LETTER
- Start a tally for this current letter as STORED_LETTER_COUNT
- I will proceed to the next letter.
- It is now my current letter
- If my current letter is equal to STORED_LETTER, I will increase STORED_LETTER_COUNT by 1
- If my current letter does not equal STORED_LETTER
- I will update my “output” to be the STORED_LETTER + STORED_LETTER_COUNT (as a string)
- Then, I will clear my tally (but have it start at 1), and change STORED_LETTER to my current letter
BAD FIRST ATTEMPT
As a human computer, I will:
- look at the current letter.
- Take note of this current letter
- Start a tally for this current letter
- If the next letter is not my current letter
- I will update my “output” to be the current letter + the current tally number
- Then, I will clear my tally (but have it start at 1)
- Then, I will formally move on to “next letter” and change current_letter to next letter
- If the next letter IS the same, I will increase the tally
- At the end, I will output whatever has been added to my “output”
Imperfect Foods
# CURRENT WORKING SCRIPT (as of 11-16-20)
from datetime import datetime
import pandas as pd
import bs4 as bs
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import presence_of_element_located
import os
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv())
MY_EMAIL = os.environ.get("IF_EMAIL")
MY_PASSWORD = os.environ.get("IF_PASSWORD")
driver = webdriver.Firefox()
wait = WebDriverWait(driver, 10)
driver.get("https://www.imperfectfoods.com/login")
first_result = wait.until(presence_of_element_located((By.ID, "login-email")))
first_result.send_keys(MY_EMAIL)
second_result = wait.until(
presence_of_element_located((By.ID, "login-password")))
second_result.send_keys(MY_PASSWORD)
second_result.submit()
try:
closeElem = wait.until(presence_of_element_located(
(By.XPATH, "//button[@aria-label='Close']")))
closeElem.click()
except:
print('trying')
driver.get('https://www.imperfectfoods.com/account/order-history')
orderElem = wait.until(presence_of_element_located(
(By.XPATH, "//button[text()='View Order']")))
orderElem.click()
soupElem = wait.until(presence_of_element_located(
(By.CSS_SELECTOR, "div[class^='Modal__Content']")))
soup = bs.BeautifulSoup(soupElem.get_attribute('innerHTML'), features='lxml')
table = soup.find('table')
df = pd.read_html(str(table))[0]
# df = pd.read_html(table.prettify(),skiprows=2, flavor="bs4")
curr_time = datetime.now().strftime('%Y-%m-%d-%s')
df.to_csv('imperfect_foods' + curr_time + '_.csv', index=False)
ls-express
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require('mongoose');
require('dotenv').config();
const app = express();
app.use(express.static("public"));
app.use(bodyParser.json());
const mongo_url = `mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@cluster0.lived.mongodb.net/${process.env.MONGO_NAMESPACE}?retryWrites=true&w=majority`
mongoose.connect(mongo_url, {useNewUrlParser: true, useUnifiedTopology: true});
var connection = mongoose.connection
app.get('/', async (req, res) => {
let results = connection.collection("test_recipes_ingredients_only").find({ recipe_name : 'Ginger Apple Moscow Mule' }).toArray()
results.then(console.log).catch(console.error)
res.status(200).send('getting results')
console.log('getting to the home page!')
})
const port = process.env.PORT || 5500;
app.listen(port, () => {
console.log(`Listening on ${port}`);
});