Skip to content

Instantly share code, notes, and snippets.

@re4lfl0w
re4lfl0w / how_to_extract_exact_url.md
Last active September 20, 2020 06:50
앞에 url만 추출할 수 있는 방법
@re4lfl0w
re4lfl0w / django_101.md
Last active January 12, 2019 05:25
Django 기초 배우기

Django 기초 배우기

강의 자료들

@re4lfl0w
re4lfl0w / psql_ignore_errors.md
Last active September 7, 2018 16:51
psql ignore errors

psql ignore errors

  • 이미 존재하는 DB에 psql로 데이터를 넣다보면 Integrity Error 가 발생할 떄가 있다. 근데 psql 옵션에는 각 한줄 한줄의 error를 무시할 수 있는 옵션이 없다.
  • 그냥 바로 넣기 때문인데... 이것 때문에 짜증이 나서 파이썬으로 한줄씩 읽으면서 DB에 넣고 Error가 발생하면 그 Data는 무시할 수 있게끔 했다.
  • 끝까지 넣기만 하면 되는거다. Data 정합성이 중요하다면 이렇게 하면 안되지만 정합성이 중요하지 않은 Data들에서는 충분히 쓸만한 소스다.
from .models import Url
def get_columns(line):
column_str = re.search(r'COPY [-_\w\.]+ \(([^\)]+)\)', line).group(1)
columns = column_str.split(',')
return [column.strip() for column in columns]
def is_start(text):
from .models import Url
def get_columns(line):
column_str = re.search(r'COPY [-_\w\.]+ \(([^\)]+)\)', line).group(1)
columns = column_str.split(',')
return [column.strip() for column in columns]
def is_start(text):
import os
import docx
from docx.document import Document
from docx.oxml.table import CT_Tbl
from docx.oxml.text.paragraph import CT_P
from docx.table import _Cell, Table
from docx.text.paragraph import Paragraph
os.chdir('C:\\OJT_Kevin\\161027_docx_parsing')
@re4lfl0w
re4lfl0w / Selenium.Python.InjectJS.py
Created July 11, 2016 00:02 — forked from anhldbk/Selenium.Python.InjectJS.py
Inject jQuery into Selenium Driver
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://www.facebook.com/')
with open('jquery-1.9.1.min.js', 'r') as jquery_js:
jquery = jquery_js.read() #read the jquery from a file
driver.execute_script(jquery) #active the jquery lib
driver.execute_script("$('#email').text('anhld')")
# Sort a list of dictionary objects by a key - case sensitive
from operator import itemgetter
mylist = sorted(mylist, key=itemgetter('name'))
# Sort a list of dictionary objects by a key - case insensitive
mylist = sorted(mylist, key=lambda k: k['name'].lower())
def dump_func_name(func):
def echo_func(*func_args, **func_kwargs):
print('')
print('Start func: {}'.format(func.__name__))
return func(*func_args, **func_kwargs)
return echo_func
class ClassName(object):
@dump_func_name