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 logging | |
from enum import IntEnum | |
from datetime import datetime | |
from typing import List, Iterable, Dict, Any, Tuple, Literal, NamedTuple, Type | |
import tenacity as tn | |
from elasticsearch.helpers import parallel_bulk | |
from app.elasticsearch.client import es_client | |
from app.db.models import BaseModel |
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
## Exercise | |
You are tasked with creating a UI that allows user to filter and view a company dataset, with the following requirements. | |
1. The app is a React app based on the structure of https://github.com/react-boilerplate/react-boilerplate. | |
2. The app connects to an HTTP API: | |
https://faker-companies.dk-dev.leadbook.com/api/v1/industries/ | |
https://faker-companies.dk-dev.leadbook.com/api/v1/companies/ | |
https://faker-companies.dk-dev.leadbook.com/api/v1/companies/?company_location=BA |
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 io | |
import time | |
from gzip import GzipFile | |
import pandas as pd | |
# https://stackoverflow.com/a/20260030/496852 | |
def iterable_to_stream(iterable, buffer_size=io.DEFAULT_BUFFER_SIZE): | |
""" |
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 re | |
from pymongo import MongoClient | |
from settings import DEST_DATABASE_URL | |
if __name__ == '__main__': | |
with open("CREDENTIALS") as f: | |
credentials = f.read().strip() |
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 time | |
from PIL import Image | |
import requests | |
from bs4 import BeautifulSoup | |
HEADERS = { | |
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:88.0) Gecko/20100101 Firefox/88.0", | |
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", | |
"Accept-Language": "en-US,en;q=0.5", |
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 time | |
from PIL import Image | |
import requests | |
from bs4 import BeautifulSoup | |
# requires brotlipy, as the server uses brotli compression | |
username = os.environ["SSM_USERNAME"] |
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 time | |
import zlib | |
from io import BytesIO | |
from zipfile import ZipFile | |
import requests | |
from bs4 import BeautifulSoup | |
HEADERS = { |
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 time | |
import random | |
from signal import signal, SIGINT, SIGTERM | |
from multiprocessing import Process, Event | |
""" | |
There are two examples: | |
(1) with graceful shutdown | |
(2) without graceful shutdown |
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 time | |
import random | |
from multiprocessing import Process | |
def f(): | |
while True: | |
time.sleep(10) | |
dice = random.randint(1, 10) |
NewerOlder