Skip to content

Commit

Permalink
YAPFify and remove unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
bcollazo committed Jul 13, 2018
1 parent 4d34088 commit 71f4f52
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
18 changes: 13 additions & 5 deletions dejavu/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker


Base = declarative_base()


Expand All @@ -23,14 +22,15 @@ class Fingerprint(Base):

id = Column(Integer, primary_key=True, nullable=False)
hash = Column(Binary(length=10), nullable=False)
song_id = Column(Integer, ForeignKey(Song.id, ondelete="CASCADE"), nullable=False)
song_id = Column(
Integer, ForeignKey(Song.id, ondelete="CASCADE"), nullable=False
)
offset = Column(Integer, nullable=False)

unique = UniqueConstraint('hash', 'song_id', 'offset')


class Database(object):

def __init__(self, url):
super(Database, self).__init__()
self.url = url
Expand Down Expand Up @@ -88,7 +88,13 @@ def insert_hashes(self, sid, hashes):
"""
fingerprints = []
for hash, offset in set(hashes):
fingerprints.append(Fingerprint(hash=binascii.unhexlify(hash), song_id=sid, offset=int(offset)))
fingerprints.append(
Fingerprint(
hash=binascii.unhexlify(hash),
song_id=sid,
offset=int(offset)
)
)

self.session.bulk_save_objects(fingerprints)

Expand All @@ -112,6 +118,8 @@ def return_matches(self, hashes):
# Get an iterable of all the hashes we need
values = [binascii.unhexlify(h) for h in mapper.keys()]

for fingerprint in self.session.query(Fingerprint).filter(Fingerprint.hash.in_(values)):
for fingerprint in self.session.query(Fingerprint).filter(
Fingerprint.hash.in_(values)
):
hash = binascii.hexlify(fingerprint.hash).upper().decode('utf-8')
yield (fingerprint.song_id, fingerprint.offset - mapper[hash])
4 changes: 3 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
secs = 5
song = djv.recognize(MicrophoneRecognizer, seconds=secs)
if song is None:
print("Nothing recognized -- did you play the song out loud so your mic could hear it? :)")
print(
"Nothing recognized -- did you play the song out loud so your mic could hear it? :)"
)
else:
print("From mic with %d seconds we recognized: %s\n" % (secs, song))

Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from setuptools import setup, find_packages

# import os, sys


def parse_requirements(requirements):
# load from requirements.txt
Expand Down

0 comments on commit 71f4f52

Please sign in to comment.