Skip to content

Instantly share code, notes, and snippets.

View bhavsarpratik's full-sized avatar

Pratik Bhavsar bhavsarpratik

View GitHub Profile
from fastprogress.fastprogress import master_bar, progress_bar
from time import sleep
mb = master_bar(range(10))
for i in mb:
for j in progress_bar(range(100), parent=mb):
sleep(0.01)
mb.child.comment = f'second bar stat'
mb.first_bar.comment = f'first bar stat'
mb.write(f'Finished loop {i}.')
import datetime
import json
import logging
import ntpath
import os
def create_folder(directory):
try:
if not os.path.exists(directory):
[loggers]
keys=root
[logger_root]
level=INFO
handlers=screen,file
[formatters]
keys=simple
import os
from abc import ABCMeta, abstractmethod
class DataProcessor(metaclass=ABCMeta):
"""Base processor to be used for all preparation."""
def __init__(self, input_directory, output_directory):
self.input_directory = input_directory
self.output_directory = output_directory
# https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-tokenfilter.html
# Explicit mappings match any token sequence on the LHS of "=>"
# and replace with all alternatives on the RHS. These types of mappings
# ignore the expand parameter in the schema.
# Examples:
i-pod, i pod => ipod,
sea biscuit, sea biscit => seabiscuit
# Equivalent synonyms may be separated with commas and give
# no explicit mapping. In this case the mapping behavior will
PUT /test_index
{
"mappings": {
"properties": {
"title": {
"type": "text",
"analyzer": "synonym_analyzer",
"search_analyzer": "synonym_analyzer"
}
PUT /test_index
{
"mappings": {
"properties": {
"title": {
"type": "text",
"analyzer": "synonym_analyzer",
"search_analyzer": "synonym_analyzer"
},
# Remove old version
brew uninstall elasticsearch-full
rm -rf /usr/local/var/lib/elasticsearch/
rm -rf /usr/local/var/log/elasticsearch/elasticsearch_account.log
rm -rf /usr/local/var/elasticsearch/plugins/
rm -rf /usr/local/etc/elasticsearch/
brew uninstall kibana-full
rm -rf /usr/local/var/lib/kibana/
rm -rf /usr/local/var/kibana/plugins/
import os
def run_command(cmd):
return os.system(cmd)
def shutdown(seconds=0, os='linux'):
"""Shutdown system after seconds given. Useful for shutting EC2 to save costs."""
if os == 'linux':
run_command('sudo shutdown -h -t sec %s' % seconds)
elif os == 'windows':
import re, inspect
# Taken and modified from https://github.com/fastai/fastcore
class Base:
def _store_attr(self, **attrs):
for n,v in attrs.items():
setattr(self, n, v)
self.__stored_args__[n] = v