Skip to content

Instantly share code, notes, and snippets.

Avatar

Harsh harshvb7

  • Cologne, Germany
View GitHub Profile
View settings.py
ES_CONNECTIONS = {
'default': {
'hosts': [http://localhost:9200],
}
}
ES_INDEXES = {
'default': [
('users', 'some_app.indexes.Article'),
]
View abstract_index.py
import datetime
import time
from django.conf import settings
import elasticsearch_dsl as es
from elasticsearch.helpers import bulk
from elasticsearch_dsl.connections import connections
View indexes.py
import elasticsearch_dsl as es
from some_app import abstract_index
from some_app.models import Post
class Article(abstract_index.DocumentBase):
title = es.Text(analyzer='snowball', fields={'raw': es.Keyword()})
body = es.Text(analyzer='snowball')
View dsl_document.py
from datetime import datetime
from elasticsearch_dsl import Document, Date, Keyword, Text
from elasticsearch_dsl.connections import connections
# Define a default Elasticsearch client
connections.create_connection(hosts=['localhost'])
class Article(Document):
title = Text(analyzer='snowball', fields={'raw': Keyword()})
body = Text(analyzer='snowball')
View elasticsearch-py-query.py
from elasticsearch import Elasticsearch
client = Elasticsearch()
response = client.search(
index="my-index",
body={
"query": {
"bool": {
"must": [{"match": {"title": "python"}}],
"must_not": [{"match": {"description": "beta"}}],
View sample_seats.json
{"SBALCONY":
[{
"t": "path",
"a": {"d": "M303.6,631.5c6.3,0,11.3,5.1,11.3,11.3s-5.1,11.3-11.3,11.3s-11.3-5.1-11.3-11.3S297.4,631.5,303.6,631.5z"}
},
{
"t": "path",
"a": {"d": "M332,642.8c6.3,0.6,10.8,6.1,10.3,12.2c-0.5,6.2-6.1,10.8-12.2,10.3c-6.2-0.5-10.8-6.1-10.3-12.2 C320.3,646.9,325.8,642.3,332,642.8z"}
},
{
View base_sample.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View adventures.py
class Solution(object):
def __init__(self):
self.arr = []
def add_product(self, name, locations):
self.arr.append((name, locations))
def get_locations(self):
data = {}
View cool.py
import datetime
import re
import urllib
from django.conf import settings
import requests
from lxml import html
from .models import Product
View requestfactory
from django.contrib.messages.storage.fallback import FallbackStorage
from django.contrib.sessions.middleware import SessionMiddleware
from django.test import RequestFactory
class TestSomeView:
def test_view(self):
request = RequestFactory().get('/')