Skip to content

Commit

Permalink
Adding a python based scraper for performers using the stash sqlite d…
Browse files Browse the repository at this point in the history
…atabase. (#230)
  • Loading branch information
Tweeticoats authored Nov 6, 2020
1 parent c4abaf7 commit 26cb3aa
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
76 changes: 76 additions & 0 deletions scrapers/stash-sqlite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import json
import sys
import sqlite3
from os import path

''' This script uses the sqlite database from another stash database and allows you to parse performers
Copy stash-go.sqlite to the scrapers directory
This script needs python3 and sqlite3
'''

def query_performers(name):
c = conn.cursor()
c.execute('SELECT name FROM performers WHERE lower(name) like lower(?)',('%' + name + '%',))
rec=[]
for row in c.fetchall():
res={}
res['name']= row[0]
rec.append(res)
return rec

def fetch_performer_name(name):
c = conn.cursor()
c.execute('SELECT name,gender,url,twitter,instagram,date(birthdate),ethnicity,country,eye_color,height,measurements,fake_tits,career_length,tattoos,piercings,aliases FROM performers WHERE lower(name) = lower(?)', (name,))

row =c.fetchone()
res={}
if row == None:
return res
res['name']= row[0]
res['gender']=row[1]
res['url']=row[2]
res['twitter']=row[3]
res['instagram']=row[4]
res['birthdate']=row[5]
res['ethnicity']=row[6]
res['country']=row[7]
res['eye_color']=row[8]
res['height']=row[9]
res['measurements']=row[10]
res['fake_tits']=row[11]
res['career_length']=row[12]
res['tattoos']=row[13]
res['piercings']=row[14]
res['aliases']=row[15]
return res


if not path.exists("stash-go.sqlite"):
print("Error, the sqlite database stash-go.sqlite does not exist in the scrapers directory.",file=sys.stderr)
print("Copy this database from another stash instance and place this in the scrapers directory",file=sys.stderr)
exit(1)


conn = sqlite3.connect('stash-go.sqlite',detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)

if sys.argv[1] == "query":
fragment = json.loads(sys.stdin.read())
print(json.dumps(fragment),file=sys.stderr)
result = query_performers(fragment['name'])
if not result:
print(f"Could not determine details for performer: `{fragment['name']}`",file=sys.stderr)
print("{}")
else:
print (json.dumps(result))
conn.close()

if sys.argv[1] == "fetch":
fragment = json.loads(sys.stdin.read())
print(json.dumps(fragment),file=sys.stderr)
result = fetch_performer_name(fragment['name'])
if not result:
print(f"Could not determine details for performer: `{fragment['name']}`",file=sys.stderr)
print("{}")
else:
print (json.dumps(result))
conn.close()
15 changes: 15 additions & 0 deletions scrapers/stash-sqlite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "stash sqlite"
performerByFragment:
action: script
script:
- python
- stash-sqlite.py
- fetch
performerByName:
action: script
script:
- python
- stash-sqlite.py
- query

# Last Updated August 12, 2020

0 comments on commit 26cb3aa

Please sign in to comment.