This file contains 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
#!/usr/bin/env python | |
#_*_ coding: utf-8 _* | |
import chardet | |
try: | |
input_file_name = input('File name?(txt or csv) ') | |
with open(input_file_name,'rb') as f_bin: | |
detected_encoding = chardet.detect(f_bin.read()) | |
print(' Detected: '+detected_encoding['encoding']) |
This file contains 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
# https://stackoverflow.com/questions/4941753/ | |
import math | |
def ncr(n, r): | |
'''Returns a combination C(n, r)''' | |
f = math.factorial | |
return int(f(n) / f(n-r) / f(r)) |
This file contains 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
#!/usr/bin/env python | |
# coding: utf-8 | |
import os | |
# Directory set up | |
my_project_root_path = input('PROJECT_ROOT_PATH = ? >> ') | |
PROJECT_ROOT_PATH = my_project_root_path | |
SOURCE_PATH = os.path.join(PROJECT_ROOT_PATH, 'source') |
This file contains 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
# Version 1.0.1 | |
# 2020-07-03 | |
import requests | |
import random | |
from bs4 import BeautifulSoup | |
# User agent definition: | |
# You can check your User Agent at ifconfig.me | |
UA_LIST = { | |
'SAFARI': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) \ |
This file contains 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 datetime import datetime | |
import pandas as pd | |
# Preparation of a data frame. | |
date_list = pd.date_range(datetime.now().date(), periods=14) | |
df = pd.DataFrame(date_list, columns=['DATE']) | |
day_dict = {'0':'Sun', '1':'Mon', '2':'Tue', '3':'Wed', | |
'4':'Thu', '5':'Fri', '6':'Sat'} | |
df['DAY'] = df.DATE.dt.strftime('%w') |
This file contains 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 json | |
import pandas as pd | |
def json2csv(file_path): | |
with open(file_path) as f: | |
my_dict = json.load(f) | |
df = pd.DataFrame.from_dict(my_dict, orient='index') | |
df.to_csv(file_path+'.csv') | |
print('DONE!') |
This file contains 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
# Page fetcher part: | |
import requests | |
from bs4 import BeautifulSoup | |
import random | |
# User agent definition: | |
# You can check your User Agent at ifconfig.me | |
UA_LIST = { | |
'SAFARI': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) \ | |
AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15', | |
'FIREFOX': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:76.0) \ |
This file contains 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 | |
from urllib.parse import quote_plus, urlunsplit | |
import requests | |
import re | |
PROJECT_ROOT_PATH = '.' | |
class GoogleResultsPage: | |
'''Query text, Results number per page -> search results response''' | |
def __init__(self, query, rslts_num): |
This file contains 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 chardet | |
with open(file_path, 'rb') as f: | |
encoding = chardet.detect(f.read()).get('encoding') | |
This file contains 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
/* CREATE */ | |
CREATE DATABASE IF NOT EXISTS db_name | |
CHARACTER SET utf8mb4 | |
COLLATE utf8mb4_0900_ai_ci; | |
-- https://dev.mysql.com/doc/refman/8.0/en/charset-mysql.html | |
CREATE TABLE IF NOT EXISTS tbl_name ( | |
id SERIAL, | |
col_name FLOAT(length), |
OlderNewer