Skip to content

Instantly share code, notes, and snippets.

# -*- coding: utf-8 -*-
import os, sys, re
lib_path = os.path.realpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'lib'))
if lib_path not in sys.path:
sys.path[0:0] = [lib_path]
# Main
import json
import random
# -*- coding: utf-8 -*-
from difflib import SequenceMatcher
def f1(string_list):
d = {}
for s in string_list:
d[s] = score(s, string_list)
return d
def score(string, string_list):
#*-*encoding: utf-8*-*
import re
PATTERN = re.compile('^(http[s]?|ftp):\/?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$')
class Search(object):
"""docstring for ClassName"""
def __init__(self):
self.list_of_links = self.get_links()
def get_filename():
dt = datetime.datetime.now()
filename = '_stored_values-{}_{}_{}'.format(dt.year, dt.month, dt.day)
return filename
def get_and_store_data(current_file_name):
questions = [
'Question 1',
'Question 2',
'Question 3',
Good morning! Here's your coding interview problem for today.
This problem was recently asked by Google.
Given a list of numbers and a number k, return whether any two numbers from the list add up to k.
For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17.
Bonus: Can you do this in one pass?
any([(a+b)==k for a in l for b in l])
---
https://www.boots.com/
['Beauty | Health | Pharmacy and Prescriptions - Boots']
['body: 3', 'images: 48', 'links: 1543', 'meta_tags: 15', 'texts: 138', 'titles: 1', 'url: 22']
Traceback (most recent call last):
File "C:\h\envs\mlpricecomp\lib\site-packages\peewee.py", line 2936, in execute_sql
cursor.execute(sql, params or ())
sqlite3.IntegrityError: UNIQUE constraint failed: selecclass_selector_through.selecclass_id, selecclass_selector_through.selector_id
During handling of the above exception, another exception occurred:
from peewee import *
if __name__ == '__main__':
# DATABASE SETUP
database = SqliteDatabase('test_db.db')
class BaseModel(Model):
class Meta:
database = database
@ronaldgreeff
ronaldgreeff / crawl-database to csv
Created July 12, 2019 16:00
script that converts data from a database of scraped data to a csv format, ready to feed into a ml model
#*-*encoding: utf-8*-*
from peewee import *
from sklearn.preprocessing import LabelEncoder
import pandas as pd
import numpy as np
import json
import re
from urllib.parse import urlparse, parse_qs
re_toke = re.compile('\W+')
elems = document.querySelectorAll('div')
l = [];
for (var i = 0, len = elems.length; i < len; i++) {
if (elems[i].offsetTop != 0) {
l.push(elems[i]);
};
};
// l.sort((a, b) => ((a.scrollHeight * a.scrollWidth) < (b.scrollHeight * b.scrollWidth)) ? 1 : -1);
// for (var i=0, len=l.length; i < len; i++) {
// console.log(l[i].offsetTop, l[i].offsetLeft, l[i].offsetHeight, l[i].offsetWidth, l[i])
function util__is_valid(value) {
var re;
re = /^[a-zA-Z][a-zA-Z0-9\-_]+$/;
return value && re.test(value);
};
function util__element(element, is_name_only) {
var c, classes, data, name, _i, _len, _ref;
name = element.tagName.toLowerCase();
if (is_name_only) {