Skip to content

Instantly share code, notes, and snippets.

View harshvb7's full-sized avatar

Harsh harshvb7

  • Cologne, Germany
View GitHub Profile
@harshvb7
harshvb7 / fix.py
Last active September 13, 2018 12:41
def get_reserved_tickets(self, performance=None):
Offer = apps.get_model('events', 'Offer')
Order = apps.get_model('events', 'Order')
offers = Offer.objects.published().filter(
state=1,
ticket_price=self,
)
if performance:
offers = offers.filter(performance=performance)
pending_tickets = offers.filter(basket__state=0).distinct() \

indexing the documents

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
from pydoc import locate
from django.conf import settings
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def __init__(self):
super(Command, self).__init__()
ES_CONNECTIONS = {
'default': {
'hosts': [http://localhost:9200],
}
}
ES_INDEXES = {
'default': [
('users', 'some_app.indexes.Article'),
]
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')
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')
from elasticsearch import Elasticsearch
client = Elasticsearch()
response = client.search(
index="my-index",
body={
"query": {
"bool": {
"must": [{"match": {"title": "python"}}],
"must_not": [{"match": {"description": "beta"}}],
class Solution(object):
def __init__(self):
self.arr = []
def add_product(self, name, locations):
self.arr.append((name, locations))
def get_locations(self):
data = {}
import datetime
import re
import urllib
from django.conf import settings
import requests
from lxml import html
from .models import Product