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
# stdout | |
logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s', | |
level=logging.INFO, datefmt='%Y/%m/%dT%H:%M:%S') | |
# file | |
logging.basicConfig(filename="log", | |
filemode='a', | |
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s', | |
datefmt='%H:%M:%S', | |
level=logging.DEBUG) |
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 requests | |
from PIL import Image | |
from io import BytesIO | |
filename = 'image.jpg' | |
r = requests.get('https://example.com/image.jpg') | |
i = Image.open(BytesIO(r.content)) | |
i.save(filename) |
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 urllib2 | |
import csv | |
from bs4 import BeautifulSoup | |
from multiprocessing.dummy import Pool # This is a thread-based Pool | |
from multiprocessing import cpu_count | |
def crawlToCSV(URLrecord): | |
OpenSomeSiteURL = urllib2.urlopen(URLrecord) | |
Soup_SomeSite = BeautifulSoup(OpenSomeSiteURL, "lxml") | |
OpenSomeSiteURL.close() |
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 random | |
import asyncio | |
from aiohttp import ClientSession | |
async def fetch(url, session): | |
async with session.get(url) as response: | |
delay = response.headers.get("DELAY") | |
date = response.headers.get("DATE") | |
print("{}:{} with delay {}".format(date, response.url, delay)) | |
return await response.read() |
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
PUT /_cluster/settings | |
{ | |
"transient": { | |
"logger.org.elasticsearch.transport": "trace" | |
} | |
} |
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
GET {index}/{type}/_search | |
{ | |
"size": 0, | |
"aggs": { | |
"{aggregation_name}": { | |
"terms": { | |
"field": "{filed_value}", | |
"size": 10 | |
} | |
} |
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
PUT /twitter/_settings | |
{ | |
"index" : { | |
"number_of_replicas" : 2 | |
} | |
} |
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 dataclasses import dataclass | |
@dataclass | |
class Card: | |
rank: str | |
suit: str | |
card = Card("Q", "hearts") | |
print(card == card) |
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 signal | |
import sys | |
import asyncio | |
import aiohttp | |
import json | |
loop = asyncio.get_event_loop() | |
client = aiohttp.ClientSession(loop=loop) | |
async def get_json(client, url): |
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
(?:4[0-9]{12}(?:[0-9]{3})?|(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\d{3})\d{11}) |
OlderNewer