release 0.5.1

This commit is contained in:
jarbasal 2019-12-13 00:50:57 +00:00
parent 03ff6f85dc
commit d87eaaae73
9 changed files with 315 additions and 571 deletions

20
CHANGELOG.md Normal file
View File

@ -0,0 +1,20 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [0.5.1] - 2019-12-12
### Changed
- Transfered ownership to [OpenJarbas](https://github.com/OpenJarbas)
- Made a changelog
- Cleaned up for python3
[unreleased]: https://github.com/OpenJarbas/PySychonaut/tree/dev
[0.5.1]: https://github.com/OpenJarbas/PySychonaut/tree/0.5.1

201
LICENSE.md Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

8
examples/catterpillar.py Normal file
View File

@ -0,0 +1,8 @@
from pysychonaut import AskTheCaterpillar
print(AskTheCaterpillar.ask_the_caterpillar("what are the effects of lsd"))
"""
Effects reported for Lsd are: visual distortions, a sense of childlike wonder, brightening of colors,racing thoughts, hue shifts, euphoria, anxiety, and confusion
"""

70
examples/erowid.py Normal file
View File

@ -0,0 +1,70 @@
from pysychonaut import Erowid
# getting substances - chemicals, pharms, herbs, animals, plants, smarts
chemicals = Erowid.get_chemicals()
print(list(chemicals[0].keys()))
names = [c["name"] for c in chemicals]
print(names)
"""
['url', 'other_names', 'name', 'effects']
[u'absinthe', u'acetylfentanyl', u'adrenochrome', u'aet', u'alcohol', u'alpha-pvp', u'amitriptyline', u'amphetamine', u'amt', u'ayahuasca', u'barbiturates', u'bk-mbdb', u'bromo-dragonfly', u'bufotenin', u'bz', u'bzp', u'caffeine', u'cannabinoids', u'capsaicin', u'carbogen', u'cathinone', u'chloroform', u'chocolate', u'cocaine / crack', u'desomorphine', u'det', u'dipt', u'dmt', u'dob', u'doc', u'doi', u'dom', u'dpt', u'dxm', u'ephedrine', u'ether', u'ethylcathinone', u'ethylene', u'ethylphenidate', u'ghb', u'ghv', u'harmala', u'heroin', u'hypocretin', u'iap', u'ibogaine', u'inhalants', u'ketamine', u'lsa', u'lsd', u'lsz', u'maois', u'mbdb', u'mcpp', u'mda', u'mde', u'mdai', u'mdma', u'mdpr', u'mdpv', u'mescaline', u'met', u'methadone', u'methamphetamines', u'methaqualone', u'methiopropamine', u'methoxetamine', u'methoxphenidine', u'methylone', u'mipt', u'mptp', u'nbome', u'nicotine', u'nitrous', u'opiates', u'opium', u'petroleum ether', u'piperazines', u'pcp', u'pma', u'pmma', u'psilocybin & psilocin', u'salvinorin b ethoxymethyl ether', u'scopolamine', u'"spice" product', u'ssris', u'tfmpp', u'thc', u'tma-2', u'toad venom', u'1,4-butanediol', u'2-aminoindan', u'2c-b', u'2c-b-fly', u'2c-c', u'2c-c-nbome', u'2c-d', u'2c-e', u'2c-i', u'2c-i-nbome', u'2c-p', u'2c-t-2', u'2c-t-4', u'2c-t-7', u'2c-t-21', u'3c-p', u'3-meo-pcp', u'4-acetoxy-det', u'4-acetoxy-dipt', u'4-acetoxy-dmt', u'4-acetoxy-mipt', u'4-fluoroamphetamine', u'4-fluoromethcathinone', u'4-hydroxy-dipt', u'4-hydroxy-met', u'4-hydroxy-mipt', u'4-hydroxy-mpt', u'4-meo-pcp', u'4-methylaminorex', u'4-methylmethcathinone', u'4-methylethcathinone', u'4-mta', u'5-it', u'5-meo-amt', u'5-meo-dalt', u'5-meo-dmt', u'5-meo-dipt', u'5-meo-mipt', u'6-apb', u'other chemicals']
"""
# parsing a substance page
chem_data = Erowid.parse_page("https://erowid.org/chemicals/lsd/lsd.shtml")
for key in chem_data:
print(key, ":", chem_data[key])
"""
info : {'basics': 'https://erowid.org/chemicals/lsd/lsd_basics.shtml', 'dose': 'https://erowid.org/chemicals/lsd/lsd_dose.shtml', 'health': 'https://erowid.org/chemicals/lsd/lsd_health.shtml', 'effects': 'https://erowid.org/chemicals/lsd/lsd_effects.shtml', 'images': 'https://erowid.org/chemicals/lsd/lsd_images.shtml', 'law': 'https://erowid.org/chemicals/lsd/lsd_law.shtml', 'chemistry': 'https://erowid.org/chemicals/lsd/lsd_chemistry.shtml'}
picture : https://erowid.org/chemicals/lsd/images/lsd_summary1.jpg
name : lsd-25
url : https://erowid.org/chemicals/lsd/
other_names : [u'acid', u'l', u'tabs', u'blotter', u'doses', u'trips']
effects : Psychedelic
chem_name : d-lysergic acid diethylamide
description : LSD is the best known and most researched psychedelic. It is the standard against which all other psychedelics are compared. It is active at extremely low doses and is most commonly available on blotter or in liquid form.
"""
# handling experience reports
trip_report = Erowid.random_experience()
print(list(trip_report.keys()))
""" ['url', 'gender', 'age', 'experience', 'drug', 'year', 'date', 'exp_id', 'dosage'] """
trip_report = Erowid.get_experience(1)
for key in trip_report:
print(key, ":", trip_report[key])
"""
url : https://erowid.org/experiences/exp.php?ID=1
gender : not specified
age : not given
15 minutes after this scary ordeal i begin to settle down, i layed down inside his warm house on the rug, touching and rubbing my hands like everywhere, everything was orgasmic feeling. I took a look at my eyes, i look like satan! it was so cool! Then after about and hour laying on the floor, other people come to his house who i dont even really know, but i just conversed with them with no feeling of stupidity, embarresment or consequences, very cool, i loved it, an hour later my eyes still were dialated but effects were over, it was fantastic
drug : ecstasy
year : 2000
date : may 30, 2000
exp_id : 1
dosage : [{'substance': u'mdma', 'form': u'(pill / tablet)', 'method': u'oral', 'ammount': u'0.5 tablets', 'time': u't+ 0:00'}, {'substance': u'mdma', 'form': u'(pill / tablet)', 'method': u'oral', 'ammount': u'0.5 tablets', 'time': u't+ 0:45'}]
"""
reports = Erowid.search_reports("1P-LSD")
print(reports[0].keys())
for report in reports[:5]:
print(report["substance"], report["url"], report["date"])
"""
['date', 'url', 'substance', 'name', 'author']
1P-ETH-LAD https://erowid.org/experiences/exp.php?ID=109647 Dec 9 2016
1P-LSD https://erowid.org/experiences/exp.php?ID=108914 Aug 1 2016
1P-LSD https://erowid.org/experiences/exp.php?ID=108138 Mar 16 2016
1P-LSD https://erowid.org/experiences/exp.php?ID=108063 Mar 11 2016
1P-LSD https://erowid.org/experiences/exp.php?ID=107880 Feb 3 2016
"""

File diff suppressed because one or more lines are too long

View File

@ -7,7 +7,7 @@ import json
__author__ = "jarbasAI" __author__ = "jarbasAI"
class Erowid(object): class Erowid:
drug_slang = { drug_slang = {
'marijuana': "thc", 'hashish': "thc", 'hash': "thc", 'weed': "thc", 'marijuana': "thc", 'hashish': "thc", 'hash': "thc", 'weed': "thc",
'marijjuana': "thc", 'cannabis': "thc", 'benzo fury': '6-apb', 'l': 'lsd', 'marijjuana': "thc", 'cannabis': "thc", 'benzo fury': '6-apb', 'l': 'lsd',
@ -243,7 +243,7 @@ class Erowid(object):
return reports return reports
class PsychonautWiki(object): class PsychonautWiki:
drug_slang = { drug_slang = {
'marijuana': "thc", 'hashish': "thc", 'hash': "thc", 'weed': "thc", 'marijuana': "thc", 'hashish': "thc", 'hash': "thc", 'weed': "thc",
'marijjuana': "thc", 'cannabis': "thc", 'benzo fury': '6-apb', 'l': 'lsd', 'marijjuana': "thc", 'cannabis': "thc", 'benzo fury': '6-apb', 'l': 'lsd',
@ -395,7 +395,7 @@ class PsychonautWiki(object):
return substances return substances
class AskTheCaterpillar(object): class AskTheCaterpillar:
drug_slang = { drug_slang = {
'marijuana': "thc", 'hashish': "thc", 'hash': "thc", 'weed': "thc", 'marijuana': "thc", 'hashish': "thc", 'hash': "thc", 'weed': "thc",
'marijjuana': "thc", 'cannabis': "thc", 'benzo fury': '6-apb', 'l': 'lsd', 'marijjuana': "thc", 'cannabis': "thc", 'benzo fury': '6-apb', 'l': 'lsd',
@ -472,3 +472,4 @@ class AskTheCaterpillar(object):
data = requests.post('https://www.askthecaterpillar.com/query', {"query": query}) data = requests.post('https://www.askthecaterpillar.com/query', {"query": query})
data = json.loads(data.text) data = json.loads(data.text)
return data["data"]["messages"][0]["content"] return data["data"]["messages"][0]["content"]

View File

@ -1,474 +0,0 @@
import requests
from bs4 import BeautifulSoup
import random
import json
__author__ = "jarbasAI"
class Erowid(object):
drug_slang = {
u'marijuana': u"thc", u'hashish': u"thc", u'hash': u"thc", u'weed': u"thc",
u'marijjuana': u"thc", u'cannabis': u"thc", u'benzo fury': u'6-apb', u'l': u'lsd',
u'x': u'mdma', u'speed': u'amphetamine', u'pepper oil': u'capsaicin', u'cpp': u'piperazines',
u'blow': u'cocaine', u'foxy': u'5-meo-dipt', u'symmetry': u'salvinorin b ethoxymethyl ether',
u'nexus': u'2c-b', u'tea': u'caffeine', u'robo': u'dxm', u' tussin': u'dxm',
u'methylethyltryptamine': u'met', u'it-290': u'amt', u'jwh-018': u'cannabinoids',
u'coffee': u'caffeine', u'mpa': u'methiopropamine', u'ergine': u'lsa',
u'harmine': u'harmala', u'mxe': u'methoxetamine',
u'4-ho-met; metocin; methylcybin': u'4-hydroxy-met', u'mdea': u'mde',
u'elavil': u'amitriptyline', u'bk-mdma': u'methylone', u'eve': u'mde',
u'a2': u'piperazines', u'dimitri': u'dmt', u'plant food': u'mdpv', u'dr. bob': u'dob', u'doctor bob': u'dob',
u'mini thins': u'ephedrine', u'meth': u'methamphetamines', u'acid': u'lsd',
u'etc.': u'nbome', u' wine': u'alcohol', u'toad venom': u'bufotenin', u' methyl-j': u'mbdb',
u'krokodil': u'desomorphine', u' 5-hydroxy-dmt': u'bufotenin', u' 3-cpp': u'mcpp',
u'special k': u'ketamine', u'ice': u'methamphetamines',
u'nrg-1': u'mdpv', u' gravel': u'alpha-pvp', u'whippits': u'nitrous', u'g': u'ghb',
u'k': u'ketamine', u' harmaline': u'harmala', u'bob': u'dob', u'4-ace': u'4-acetoxy-dipt',
u'quaaludes': u'methaqualone', u' opium': u'opiates', u'u4ea': u'4-methylaminorex',
u'meopp': u'piperazines', u'methcathinone': u'cathinone', u'horse': u'heroin',
u'haoma': u'harmala', u'unknown': u'"spice" product', u'4-b': u'1,4-butanediol',
u'naptha': u'petroleum ether', u'beer': u'alcohol', u'bees': u'2c-b',
u'2c-bromo-fly': u'2c-b-fly', u'flatliner': u'4-mta', u'orexins': u'hypocretin',
u"meduna's mixture": u'carbogen', u'bdo': u'1,4-butanediol',
u'fatal meperedine-analog contaminant': u'mptp', u'piperazine': u'bzp', u'4-ma': u'pma',
u'paramethoxyamphetamine': u'pma', u'eden': u'mbdb', u'theobromine': u'chocolate',
u'la-111': u'lsa', u'lysergamide': u'lsa', u'yaba': u'methamphetamines',
u'ethyl cat': u'ethylcathinone', u'stp': u'dom', u'2c-c-nbome': u'nbome',
u'morphine': u'opiates', u'flakka': u'alpha-pvp', u'yage': u'ayahuasca',
u'ecstasy': u'mdma', u'ludes': u'methaqualone', u'golden eagle': u'4-mta',
u'4-mma': u'pmma', u'o-dms': u'5-meo-amt', u'liquor': u'alcohol',
u'mephedrone': u'4-methylmethcathinone', u'1': u'1,4-butanediol', u'phencyclidine': u'pcp',
u'crystal': u'methamphetamines', u'pink adrenaline': u'adrenochrome',
u'4-mec': u'4-methylethcathinone', u'green fairy': u'absinthe', u'laa': u'lsa',
u'cp 47': u'cannabinoids', u'paramethoxymethylamphetamine': u'pmma',
u'5-meo': u'5-meo-dmt', u'alpha': u'5-meo-amt', u'mescaline-nbome': u'nbome',
u'25c-nbome': u'2c-c-nbome', u'flephedrone': u'4-fluoromethcathinone',
u'bzp': u'piperazines', u'codeine': u'opiates', u'foxy methoxy': u'5-meo-dipt',
u'25i-nbome': u'2c-i-nbome', u'3c-bromo-dragonfly': u'bromo-dragonfly', u'mdai': u'mdai',
u'tfmpp': u'piperazines'
}
@staticmethod
def extract_experience_text(text):
try:
begin_delimiter = '<!-- Start Body -->'
begin = text.index(begin_delimiter) + len(begin_delimiter)
end = text.index('<!-- End Body -->')
return text[begin:end].strip().replace("<BR>", "\n").replace("<br>", "\n").replace("\n\n", " ").replace("<br/>", "\n")
except ValueError:
return ''
@staticmethod
def _extract_list(base_url):
response = requests.get(base_url).text
soup = BeautifulSoup(response, "lxml")
table = soup.find('table', {'class': 'topic-chart-surround'})
categories = table.find_all("tr", {'class': 'topic-surround'})[1:]
fields = []
for cat in categories:
chem_data = {}
name = cat.find("td", {'class': 'topic-name'})
chem_data["url"] = base_url + name.find("a")["href"]
chem_data["name"] = name.getText().strip().lower()
chem_data["other_names"] = cat.find("td", {'class': 'topic-common'}).getText().strip().lower()
chem_data["effects"] = cat.find("td", {'class': 'topic-desc'}).getText().strip().lower()
fields.append(chem_data)
return fields
@staticmethod
def get_experience(exp_id):
base_url = 'https://erowid.org/experiences/exp.php'
url = base_url+"?ID="+str(exp_id)
data = {"exp_id": exp_id, "url": url}
try:
response = requests.get(url).text
experience = Erowid.extract_experience_text(response)
soup = BeautifulSoup(response, "lxml")
name = soup.find('div', {'class': 'title'}).getText().strip()
author = soup.find('div', {'class': 'author'}).getText().strip()
drug = soup.find('div', {'class': 'substance'}).getText().strip().lower().replace("/", ", ")
experience_data = soup.find('table', {'class': 'footdata'}).getText().strip().lower().split("\n")
data["name"] = name
data["author"] = author
data["substance"] = drug
data["experience"] = experience
data["year"] = experience_data[0].split("expid:")[0].replace("exp year: ", "").strip()
data["gender"] = experience_data[1].replace("gender: ", "").strip()
data["age"] = experience_data[2].replace("age at time of experience: ", "").strip()
data["date"] = experience_data[3].replace("published: ", "").split("views:")[0].strip()
data["dosage"] = []
dosage_table = soup.find('table', {'class': 'dosechart'})
ts = dosage_table.find_all("td", {'align': 'right'})
ammount = dosage_table.find_all("td", {'class': 'dosechart-amount'})
method = dosage_table.find_all("td", {'class': 'dosechart-method'})
substance= dosage_table.find_all("td", {'class': 'dosechart-substance'})
form = dosage_table.find_all("td", {'class': 'dosechart-form'})
for i in range(len(ts)):
dosage_data = {}
dosage_data["time"] = ts[i].getText().lower().replace("dose:", "").strip()
dosage_data["ammount"] = ammount[i].getText().strip().lower()
dosage_data["method"] = method[i].getText().strip().lower()
dosage_data["substance"] = substance[i].getText().strip().lower()
dosage_data["form"] = form[i].getText().strip().lower()
data["dosage"].append(dosage_data)
except Exception as e:
return None
return data
@staticmethod
def get_categories():
base_url = 'https://erowid.org/experiences/exp_list.shtml'
response = requests.get(base_url).text
categories = []
for sub in response.split("<!-- Start ")[1:]:
sub = sub[:sub.find(" -->")]
categories.append(sub)
return categories
@staticmethod
def get_pharms():
base_url = 'https://erowid.org/pharms/'
return Erowid._extract_list(base_url)
@staticmethod
def get_chemicals():
base_url = 'https://erowid.org/chemicals/'
return Erowid._extract_list(base_url)
@staticmethod
def get_plants():
base_url = 'https://erowid.org/plants/'
return Erowid._extract_list(base_url)
@staticmethod
def get_herbs():
base_url = 'https://erowid.org/herbs/'
return Erowid._extract_list(base_url)
@staticmethod
def get_smarts():
base_url = 'https://erowid.org/smarts/'
return Erowid._extract_list(base_url)
@staticmethod
def get_animals():
base_url = 'https://erowid.org/animals/'
return Erowid._extract_list(base_url)
@staticmethod
def parse_page(url):
base_url = url
if ".shtml" in base_url:
base_url = "/".join(base_url.split("/")[:-1]) + "/"
data = {"url": base_url}
response = requests.get(url).text
soup = BeautifulSoup(response, "lxml")
data["name"] = soup.find('div', {'class': 'title-section'}).getText().strip().lower()
picture = soup.find('div', {'class': "summary-card-topic-image"}).find("img")
if picture:
picture = base_url + picture["src"]
else:
picture = ""
data["picture"] = picture
data["other_names"] = [n.strip().lower() for n in soup.find('div', {'class': 'sum-common-name'}).getText().split(";")]
data["description"] = soup.find('div', {'class': "sum-description"}).getText()
info = soup.find('div', {'class': "summary-card-icon-surround"}).find_all("a")
urls = {}
for i in info:
url = base_url + i["href"]
name = i.find("img")["alt"].strip().lower()
urls[name] = url
data["info"] = urls
if "/chem" in url or "/pharms" in url or "/smarts" in url:
data["chem_name"] = soup.find('div', {'class': "sum-chem-name"}).getText()
data["effects"] = soup.find('div', {'class': "sum-effects"}).getText()
elif "/animals" in url or "/plants" in url:
animal_data = soup.find_all('div', {'class': "fgs-row"})
data["family"] = animal_data[0].find('div', {'class': "family"}).getText()
data["genus"] = animal_data[1].find('div', {'class': "genus"}).getText()
data["species"] = animal_data[2].find('div', {'class': "species"}).getText()
data["effects"] = soup.find('div', {'class': "sum-effects"}).getText()
elif "/herbs" in url:
animal_data = soup.find_all('div', {'class': "fgs-row"})
data["family"] = animal_data[0].find('div', {'class': "family"}).getText()
data["genus"] = animal_data[1].find('div', {'class': "genus"}).getText()
data["species"] = animal_data[2].find('div', {'class': "species"}).getText()
data["uses"] = soup.find('div', {'class': "sum-uses"}).getText()
return data
@staticmethod
def random_experience():
exp = None
while exp is None:
exp = Erowid.get_experience(random.randint(1, 111451))
return exp
@staticmethod
def search_reports(search_term, order="substance"):
base_url = "https://erowid.org/experiences/"
search_term = search_term.replace(" ", "+")
url = base_url + "exp.cgi?Str=" + search_term
if order == "substance":
url += "&OldSort=SA"
elif order in ["date", "recent"]:
url += "&OldSort=PDD"
elif order in ["old", "older", "oldest"]:
url += "&OldSort=PDA"
elif order in ["rating"]:
url += "&OldSort=RA"
elif order is not None:
url += "&OldSort=" + order
response = requests.get(url).text
soup = BeautifulSoup(response, "lxml")
table = soup.find('table', {'class': "exp-list-table"})
table = table.find_all("tr", {'class': ""})[2:]
reports = []
for r in table:
report = {}
fields = r.find_all("td")[1:]
report["name"] = fields[0].getText()
report["author"] = fields[1].getText()
report["substance"] = fields[2].getText()
report["date"] = fields[3].getText()
report["url"] = base_url + r.find("a")["href"]
report["exp_id"] = report["url"].split("=")[1]
reports.append(report)
return reports
class PsychonautWiki(object):
drug_slang = {
u'marijuana': u"thc", u'hashish': u"thc", u'hash': u"thc", u'weed': u"thc",
u'marijjuana': u"thc", u'cannabis': u"thc", u'benzo fury': u'6-apb', u'l': u'lsd',
u'x': u'mdma', u'speed': u'amphetamine', u'pepper oil': u'capsaicin', u'cpp': u'piperazines',
u'blow': u'cocaine', u'foxy': u'5-meo-dipt', u'symmetry': u'salvinorin b ethoxymethyl ether',
u'nexus': u'2c-b', u'tea': u'caffeine', u'robo': u'dxm', u' tussin': u'dxm',
u'methylethyltryptamine': u'met', u'it-290': u'amt', u'jwh-018': u'cannabinoids',
u'coffee': u'caffeine', u'mpa': u'methiopropamine', u'ergine': u'lsa',
u'harmine': u'harmala', u'mxe': u'methoxetamine',
u'4-ho-met; metocin; methylcybin': u'4-hydroxy-met', u'mdea': u'mde',
u'elavil': u'amitriptyline', u'bk-mdma': u'methylone', u'eve': u'mde',
u'a2': u'piperazines', u'dimitri': u'dmt', u'plant food': u'mdpv', u'dr. bob': u'dob', u'doctor bob': u'dob',
u'mini thins': u'ephedrine', u'meth': u'methamphetamines', u'acid': u'lsd',
u'etc.': u'nbome', u' wine': u'alcohol', u'toad venom': u'bufotenin', u' methyl-j': u'mbdb',
u'krokodil': u'desomorphine', u' 5-hydroxy-dmt': u'bufotenin', u' 3-cpp': u'mcpp',
u'special k': u'ketamine', u'ice': u'methamphetamines',
u'nrg-1': u'mdpv', u' gravel': u'alpha-pvp', u'whippits': u'nitrous', u'g': u'ghb',
u'k': u'ketamine', u' harmaline': u'harmala', u'bob': u'dob', u'4-ace': u'4-acetoxy-dipt',
u'quaaludes': u'methaqualone', u' opium': u'opiates', u'u4ea': u'4-methylaminorex',
u'meopp': u'piperazines', u'methcathinone': u'cathinone', u'horse': u'heroin',
u'haoma': u'harmala', u'unknown': u'"spice" product', u'4-b': u'1,4-butanediol',
u'naptha': u'petroleum ether', u'beer': u'alcohol', u'bees': u'2c-b',
u'2c-bromo-fly': u'2c-b-fly', u'flatliner': u'4-mta', u'orexins': u'hypocretin',
u"meduna's mixture": u'carbogen', u'bdo': u'1,4-butanediol',
u'fatal meperedine-analog contaminant': u'mptp', u'piperazine': u'bzp', u'4-ma': u'pma',
u'paramethoxyamphetamine': u'pma', u'eden': u'mbdb', u'theobromine': u'chocolate',
u'la-111': u'lsa', u'lysergamide': u'lsa', u'yaba': u'methamphetamines',
u'ethyl cat': u'ethylcathinone', u'stp': u'dom', u'2c-c-nbome': u'nbome',
u'morphine': u'opiates', u'flakka': u'alpha-pvp', u'yage': u'ayahuasca',
u'ecstasy': u'mdma', u'ludes': u'methaqualone', u'golden eagle': u'4-mta',
u'4-mma': u'pmma', u'o-dms': u'5-meo-amt', u'liquor': u'alcohol',
u'mephedrone': u'4-methylmethcathinone', u'1': u'1,4-butanediol', u'phencyclidine': u'pcp',
u'crystal': u'methamphetamines', u'pink adrenaline': u'adrenochrome',
u'4-mec': u'4-methylethcathinone', u'green fairy': u'absinthe', u'laa': u'lsa',
u'cp 47': u'cannabinoids', u'paramethoxymethylamphetamine': u'pmma',
u'5-meo': u'5-meo-dmt', u'alpha': u'5-meo-amt', u'mescaline-nbome': u'nbome',
u'25c-nbome': u'2c-c-nbome', u'flephedrone': u'4-fluoromethcathinone',
u'bzp': u'piperazines', u'codeine': u'opiates', u'foxy methoxy': u'5-meo-dipt',
u'25i-nbome': u'2c-i-nbome', u'3c-bromo-dragonfly': u'bromo-dragonfly', u'mdai': u'mdai',
u'tfmpp': u'piperazines'}
def __init__(self):
self.substance_list = self.get_substance_list()
self.substances = self.get_substance_data()
def extract_substance_name(self, sentence):
words = sentence.lower().split(" ")
found = False
# check for drug slang names
for substance in self.drug_slang:
substance = substance.lower()
name = self.drug_slang[substance].strip()
for idx, word in enumerate(words):
if substance == word:
found = name
break
# check substance list
for substance in self.substance_list:
substance = substance.lower()
for idx, word in enumerate(words):
if substance == word:
found = substance
break
if found:
# match case, psychonaut wiki doesn't like lower-case
subs = self.substance_list
substances = [s.lower() for s in subs]
substance = found.lower()
if substance in substances:
found = subs[substances.index(substance)]
return found
def search_psychonaut_wiki(self, substance):
s = self.extract_substance_name(substance)
if not s:
print "Warning, this query does not seem to contain a valid substance name"
else:
substance = s
url = "https://api.psychonautwiki.org/?query=%7B%0A%20%20%20%20substances(query%3A%20%22" + substance + "%22)%20%7B%0A%20%20%20%20%20%20%20%20name%0A%0A%20%20%20%20%20%20%20%20%23%20routes%20of%20administration%0A%20%20%20%20%20%20%20%20roas%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20name%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20dose%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20units%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20threshold%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20heavy%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20common%20%7B%20min%20max%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20light%20%7B%20min%20max%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20strong%20%7B%20min%20max%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20duration%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20afterglow%20%7B%20min%20max%20units%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20comeup%20%7B%20min%20max%20units%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20duration%20%7B%20min%20max%20units%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20offset%20%7B%20min%20max%20units%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20onset%20%7B%20min%20max%20units%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20peak%20%7B%20min%20max%20units%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20total%20%7B%20min%20max%20units%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20bioavailability%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20min%20max%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%23%20subjective%20effects%0A%20%20%20%20%20%20%20%20effects%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20name%20url%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D"
return json.loads(requests.get(url).text)["data"]
@staticmethod
def get_substance_list():
base_url = "https://psychonautwiki.org/wiki/Summary_index"
response = requests.get(base_url).text
soup = BeautifulSoup(response, "lxml")
table = soup.findAll('div', {'class': 'panel radius'})
substances = []
for panel in table:
subs = panel.find_all("li", {"class": "featured list-item"})
for s in subs:
subcat = s.find("span", {"class": "mw-headline"})
i = 0
if subcat is not None:
subcat = subcat.getText()
s = s.find_all("a")
if subcat is not None and s[0].getText() == subcat:
i = 1
for substance in s[i:]:
sub_name = substance.getText().replace("/Summary", "").replace("(page does not exist)", "").strip()
substances.append(sub_name)
return substances
@staticmethod
def get_substance_data():
base_url = "https://psychonautwiki.org/wiki/Summary_index"
response = requests.get(base_url).text
soup = BeautifulSoup(response, "lxml")
table = soup.findAll('div', {'class': 'panel radius'})
substances = {}
for panel in table:
categorie = panel.find('span', {'class': 'mw-headline'})
name = categorie["id"]
try:
url = "https://psychonautwiki.org/" + categorie.find("a")["href"]
except:
url = None
if name not in substances:
substances[name] = {"url": url}
subs = panel.find_all("li", {"class": "featured list-item"})
for s in subs:
subcat = s.find("span", {"class": "mw-headline"})
i = 0
if subcat is not None:
subcat = subcat.getText()
substances[name][subcat] = {}
s = s.find_all("a")
if subcat is not None and s[0].getText() == subcat:
try:
url = "https://psychonautwiki.org/" + s[0]["href"]
except:
url = None
i = 1
substances[name][subcat]["url"] = url
for substance in s[i:]:
sub_name = substance.getText().replace("/Summary", "").replace("(page does not exist)", "").strip()
if subcat:
substances[name][subcat][sub_name] = "https://psychonautwiki.org/" + substance["href"]
else:
substances[name][sub_name] = "https://psychonautwiki.org/" + substance["href"]
return substances
class AskTheCaterpillar(object):
drug_slang = {
u'marijuana': u"thc", u'hashish': u"thc", u'hash': u"thc", u'weed': u"thc",
u'marijjuana': u"thc", u'cannabis': u"thc", u'benzo fury': u'6-apb', u'l': u'lsd',
u'x': u'mdma', u'speed': u'amphetamine', u'pepper oil': u'capsaicin', u'cpp': u'piperazines',
u'blow': u'cocaine', u'foxy': u'5-meo-dipt', u'symmetry': u'salvinorin b ethoxymethyl ether',
u'nexus': u'2c-b', u'tea': u'caffeine', u'robo': u'dxm', u' tussin': u'dxm',
u'methylethyltryptamine': u'met', u'it-290': u'amt', u'jwh-018': u'cannabinoids',
u'coffee': u'caffeine', u'mpa': u'methiopropamine', u'ergine': u'lsa',
u'harmine': u'harmala', u'mxe': u'methoxetamine',
u'4-ho-met; metocin; methylcybin': u'4-hydroxy-met', u'mdea': u'mde',
u'elavil': u'amitriptyline', u'bk-mdma': u'methylone', u'eve': u'mde',
u'a2': u'piperazines', u'dimitri': u'dmt', u'plant food': u'mdpv', u'dr. bob': u'dob',
u'doctor bob': u'dob',
u'mini thins': u'ephedrine', u'meth': u'methamphetamines', u'acid': u'lsd',
u'etc.': u'nbome', u' wine': u'alcohol', u'toad venom': u'bufotenin', u' methyl-j': u'mbdb',
u'krokodil': u'desomorphine', u' 5-hydroxy-dmt': u'bufotenin', u' 3-cpp': u'mcpp',
u'special k': u'ketamine', u'ice': u'methamphetamines',
u'nrg-1': u'mdpv', u' gravel': u'alpha-pvp', u'whippits': u'nitrous', u'g': u'ghb',
u'k': u'ketamine', u' harmaline': u'harmala', u'bob': u'dob', u'4-ace': u'4-acetoxy-dipt',
u'quaaludes': u'methaqualone', u' opium': u'opiates', u'u4ea': u'4-methylaminorex',
u'meopp': u'piperazines', u'methcathinone': u'cathinone', u'horse': u'heroin',
u'haoma': u'harmala', u'unknown': u'"spice" product', u'4-b': u'1,4-butanediol',
u'naptha': u'petroleum ether', u'beer': u'alcohol', u'bees': u'2c-b',
u'2c-bromo-fly': u'2c-b-fly', u'flatliner': u'4-mta', u'orexins': u'hypocretin',
u"meduna's mixture": u'carbogen', u'bdo': u'1,4-butanediol',
u'fatal meperedine-analog contaminant': u'mptp', u'piperazine': u'bzp', u'4-ma': u'pma',
u'paramethoxyamphetamine': u'pma', u'eden': u'mbdb', u'theobromine': u'chocolate',
u'la-111': u'lsa', u'lysergamide': u'lsa', u'yaba': u'methamphetamines',
u'ethyl cat': u'ethylcathinone', u'stp': u'dom', u'2c-c-nbome': u'nbome',
u'morphine': u'opiates', u'flakka': u'alpha-pvp', u'yage': u'ayahuasca',
u'ecstasy': u'mdma', u'ludes': u'methaqualone', u'golden eagle': u'4-mta',
u'4-mma': u'pmma', u'o-dms': u'5-meo-amt', u'liquor': u'alcohol',
u'mephedrone': u'4-methylmethcathinone', u'1': u'1,4-butanediol', u'phencyclidine': u'pcp',
u'crystal': u'methamphetamines', u'pink adrenaline': u'adrenochrome',
u'4-mec': u'4-methylethcathinone', u'green fairy': u'absinthe', u'laa': u'lsa',
u'cp 47': u'cannabinoids', u'paramethoxymethylamphetamine': u'pmma',
u'5-meo': u'5-meo-dmt', u'alpha': u'5-meo-amt', u'mescaline-nbome': u'nbome',
u'25c-nbome': u'2c-c-nbome', u'flephedrone': u'4-fluoromethcathinone',
u'bzp': u'piperazines', u'codeine': u'opiates', u'foxy methoxy': u'5-meo-dipt',
u'25i-nbome': u'2c-i-nbome', u'3c-bromo-dragonfly': u'bromo-dragonfly', u'mdai': u'mdai',
u'tfmpp': u'piperazines'}
def __init__(self):
self.substance_list = PsychonautWiki.get_substance_list()
def fix_substance_names(self, sentence):
words = sentence.lower().split(" ")
found = False
# check for drug slang names
for substance in self.drug_slang:
substance = substance.lower()
name = self.drug_slang[substance].strip()
for idx, word in enumerate(words):
if substance == word:
words[idx] = name
found = True
# check substance list
for substance in self.substance_list:
substance = substance.lower()
for idx, word in enumerate(words):
if substance == word:
words[idx] = substance
found = True
if found:
return " ".join(words)
# probably not talking about drugs
return found
@staticmethod
def ask_the_caterpillar(query):
data = requests.post('https://www.askthecaterpillar.com/query', {"query": query})
data = json.loads(data.text)
return data["data"]["messages"][0]["content"]

View File

@ -1,8 +1,4 @@
## PySychonaut ## PySychonaut
[![Donate with Bitcoin](https://en.cryptobadges.io/badge/micro/1QJNhKM8tVv62XSUrST2vnaMXh5ADSyYP8)](https://en.cryptobadges.io/donate/1QJNhKM8tVv62XSUrST2vnaMXh5ADSyYP8)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/jarbasai)
<span class="badge-patreon"><a href="https://www.patreon.com/jarbasAI" title="Donate to this project using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon donate button" /></a></span>
[![Say Thanks!](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://saythanks.io/to/JarbasAl)
Unofficial python api for [Erowid](http://erowid.org/), [PsychonautWiki](http://psychonautwiki.org/) and [AskTheCaterpillar](http://askthecaterpillar.com/) Unofficial python api for [Erowid](http://erowid.org/), [PsychonautWiki](http://psychonautwiki.org/) and [AskTheCaterpillar](http://askthecaterpillar.com/)

View File

@ -2,12 +2,12 @@ from setuptools import setup
setup( setup(
name='PySychonaut', name='PySychonaut',
version='0.5', version='0.5.1',
packages=['pysychonaut'], packages=['pysychonaut'],
url='https://github.com/JarbasAl/PySychonaut', url='https://github.com/OpenJarbas/PySychonaut',
license='MIT', license='apache2.0',
author='jarbasAI', author='jarbasAI',
author_email='jarbasai@mailfence.com', author_email='jarbasai@mailfence.com',
description='unnoficial erowid, psychonaut wiki and ask_the_caterpillar apis', description='unnoficial erowid, psychonaut wiki and ask_the_caterpillar apis',
install_requires=["lxml", "bs4"] install_requires=["lxml", "bs4", "requests"]
) )