This text is italic
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
def json_flat_dict(da): | |
v = {} | |
for i in da: | |
if type(da[i]) == dict: | |
g = json_flat_dict(da[i]) | |
for j in g: | |
v[i + '__' + j] = g[j] | |
else: | |
v[i] = da[i] | |
return v |
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 a virtual env in a folder, to create virtual env: | |
virtualenv -p python3 env | |
env is the name of environment | |
a folder with env name is created, to activate the environment | |
source env/bin/activate |
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
after activating virtual environment | |
to create project | |
django-admin startproject 'project_name' | |
to create an app or module in the project | |
cd into the project folder |
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 | |
import re | |
api_key = 'AIzaSyDb3Rl__2TZ1uo-P9BBTZo29FGQ7OlvdLM' | |
website = input('enter a website with format "http://www.example.com" : ') | |
regex = re.compile( | |
r'^(?:http)s?://' # http:// or https:// |
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
class LoginRequiredMixin(object): | |
""" | |
View mixin which requires that the user is authenticated. | |
""" | |
@method_decorator(login_required) | |
def dispatch(self, request, *args, **kwargs): | |
return super(LoginRequiredMixin, self).dispatch( | |
self, request, *args, **kwargs) |
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
temp = [] | |
with open('JSON_TO_CSV_2019-01-30-18-56-22-101458.csv') as f: | |
r = csv.reader(f) | |
head = next(r) | |
for i in r: | |
dict_ ={} | |
for j,k in zip(head,i): | |
dict_[j]=k | |
temp.append(dict_) | |
dict_ = {} |
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
list_of_dicts = [ | |
{ "prop": 1, "attr": 2 }, | |
{ "prop": 3, "attr": 4 } | |
# ... | |
] | |
with open(filepath, 'w') as f: | |
f.write('[') |
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 csv | |
import json | |
def csv_to_json_conversion(file_name): | |
json_file_name = 'jsonl__42kod.json' | |
with open(file_name, 'r') as f: | |
r = csv.reader(f) | |
head = next(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
<script> | |
// the anchor tag is the pagination link | |
$("a[rel='page']").click(function(e){ | |
e.preventDefault(); | |
$('#search_filter').attr("action", $(this).attr("href")); | |
$('#search_filter').submit(); | |
}); | |
// post to a view function, instead of get | |
</script> |
OlderNewer