Skip to content

Instantly share code, notes, and snippets.

View dchaplinsky's full-sized avatar

Dmitry Chaplinsky dchaplinsky

View GitHub Profile
@dchaplinsky
dchaplinsky / declarations_api.py
Last active December 3, 2021 00:06
Simple example of how to export all assets declarations from declarations.com.ua website.
import requests
import json
from time import sleep
data = []
print("Fetching page #%s" % 1)
r = requests.get("http://declarations.com.ua/search?format=opendata").json()
data += r["results"]["object_list"]
# -*- coding: utf-8 -*-
# Copyright 2016 Matt Martz
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@dchaplinsky
dchaplinsky / redis_tools.py
Created December 16, 2013 11:10
Very small but handy tool to export keys from redis to json by wildcards and load them back. Dead simple, no error processing, no warnings, no support for huge datasets (beware, dumping/loading 1GB of data will most likely consume way more ram that you are happy to allocate for that purpose)
import os
import sys
from redis import Redis
import argparse
import simplejson as json
import settings
redis_client = Redis(host=settings.REDIS_HOST, port=settings.REDIS_PORT,
db=settings.REDIS_DB)
{
"lotNumberStr": "27059380",
"ln": 27059380,
"mkn": "DODGE",
"lm": "CHALLENGER",
"lcy": 2018,
"fv": "2C3CDZGGXJH289026",
"la": 24998,
"rc": 27890,
"obc": "A",
--- ../venv/lib/python3.6/site-packages/flask_lambda.py 2017-07-04 02:51:23.000000000 +0300
+++ lambdas/venues_finder/venues_finder/lambdify.py 2017-07-10 16:49:41.000000000 +0300
@@ -31,7 +31,7 @@
except ImportError:
from io import StringIO
-from werkzeug.wrappers import BaseRequest
+from werkzeug.wrappers import BaseRequest, Response
@dchaplinsky
dchaplinsky / print_statement.py
Created November 5, 2014 19:03
A neat way to print raw SQL for SQLAlchemy statement with dialect specific stuff and all params substituted.
from sqlalchemy.dialects import postgresql
print(YOUR_SQL.statement.compile(dialect=postgresql.dialect(), compile_kwargs={"literal_binds": True}))
@dchaplinsky
dchaplinsky / double_ip_test.py
Created January 4, 2014 00:09
Simple scrapy spider to utilize bindaddress meta param
from scrapy.spider import BaseSpider
from scrapy.conf import settings
from scrapy.http import Request
from random import choice
class DoubleIPSpider(BaseSpider):
name = "double_ip_test"
allowed_domains = ["httpbin.org"]
from rpy2 import robjects
from rpy2.robjects.packages import importr, STAP
jsonlite = importr("jsonlite")
with open('function_to_test_decl_read_incomr_process.R', 'r') as f:
s = f.read()
proc = STAP(s, "declaration_income_processing")
with open("declarations_bank/data/01/авраменко_максим_ігорович_01a15d65-8f55-4c59-86f3-c6a58bc2f37b.json", "r") as fp:
<?xml version="1.0" encoding="UTF-8"?>
<company>
<name>ПАТ «БАНК КРЕДИТ ДНІПРО»</name>
<owners>
<owner>
<share>100</share>
<company>
<name>БРЕНКРОФТ ЕНТЕРПРАЙЗЕЗ ЛІМІТЕД</name>
<name_en>BRANCROFT ENTERPRISES LIMITED</name_en>
<country>Кіпр</country>
{
"name": "ПАТ «БАНК КРЕДИТ ДНІПРО»",
"owners": [
{
"share": "100",
"company": {
"name": "БРЕНКРОФТ ЕНТЕРПРАЙЗЕЗ ЛІМІТЕД",
"name_en": "BRANCROFT ENTERPRISES LIMITED",
"country": "Кіпр",
"owners": [