Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
tameen committed May 12, 2023
1 parent 68b57f3 commit df8c63f
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 7 deletions.
2 changes: 1 addition & 1 deletion prod_config/quranref_api.wsgi
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ from pyramid.paster import get_app, setup_logging

here = os.path.dirname(os.path.realpath(__file__))
ini_path = here + '/quranref_api.ini'
setup_logging(ini_path)
(ini_path)
application = get_app(ini_path, 'main')
5 changes: 3 additions & 2 deletions quranref/graph_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from arango import ArangoClient
from arango_orm import Database

log = logging.getLogger(__name__)

log = logging.getLogger(__name__)
global gdb
gdb = None


def connect(server, port, username, password, db_name):

global gdb


client = ArangoClient(hosts=f"http://{server}:{port}")
db = client.db(db_name, username=username, password=password)
Expand Down
4 changes: 2 additions & 2 deletions quranref/scripts/arabic_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def import_ayas(text_name, filename):
log.info("Done importing!")


def main(argv=sys.argv): # pylint: disable=W0102
def main(argv): # pylint: disable=W0102
if len(argv) != 4:
usage(argv)

load_project_settings()

config_uri = argv[1]
config_uri = argv[2]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
do_config({'__file__': config_uri}, **settings)
Expand Down
98 changes: 98 additions & 0 deletions quranref/scripts/cli2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import os
import sys
from typing import Optional
import typer
from database_conn import *
from arango import ArangoClient
from pyramid.paster import get_appsettings, setup_logging
from quranref.__init__ import load_project_settings, do_config

def usage(argv):
cmd = os.path.basename(argv[0])
print(('usage: %s <config_uri>\n'
'(example: "%s development.ini")' % (cmd, cmd)))
sys.exit(1)

def _get_graph():
from quranref.graph_models import gdb
from quranref.graph_models.quran_graph import QuranGraph
graph = QuranGraph(connection=gdb)

return gdb, QuranGraph, graph

def create_graph():
gdb, _, graph = _get_graph()
gdb.create_graph(graph)

app = typer.Typer()
quranref_app = typer.Typer()
app.add_typer(quranref_app, name="quranref")

"""
@app.command()
def add(name:str, key:str):
if name:
try:
doc = ayasCollection.createDocument()
doc["name"] = name
doc._key = key
doc.save()
print("Saved")
#typer.echo(f"Hello {name}")
except:
print("ERROR")
else:
print("Please Insert Correctly")
#typer.echo("Thanks")
"""


@app.command()
def getbynumber(number:int):
aql="FOR a IN ayas FILTER a.aya_number == %s RETURN a" %(number)
#print(aql)
queryRes = db.AQLQuery(aql,rawResults=True, batchSize=100)
print("HERE I AM")
for key in queryRes:
print(key)

@app.command()
def showall():
aql="FOR a IN ayas RETURN a"
queryRes = db.AQLQuery(aql,rawResults=True, batchSize=100)
for key in queryRes:
print(key)

@quranref_app.command("populate")
def populate(val:str):
client = ArangoClient()
dbb = client.db('quranref',username='kashif',password='compulife')
if db.has_graph('quran_graph'):
quran_graph = db.graph('quran_graph')
else:
quran_graph = db.create_graph('quran_graph')

load_project_settings()

# create_graph()
gdb, QuranGraph, _ = _get_graph()
db_objects = [QuranGraph]
gdb.create_all(db_objects)
gdb, QuranGraph, _ = _get_graph()
db_objects = [QuranGraph]
print(db_objects)
gdb.create_all(db_objects)
print(quran_graph.name)
print(quran_graph.db_name)
print(quran_graph.vertex_collections())
print(quran_graph.edge_definitions())
#print(dbb.graphs());
#gdb, QuranGraph,_= _get_graph()
#db_objects = [QuranGraph]
#print(gdb.graphs['Surah'])
print("quranref.scripts.populate:main")


if __name__=="__main__":
app()

2 changes: 1 addition & 1 deletion quranref/scripts/surah_info_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def import_surahs():
log.info("Done importing!")


def main(argv=sys.argv): # pylint: disable=W0102
def surah_info_import(argv): # pylint: disable=W0102
if len(argv) != 2:
usage(argv)

Expand Down
2 changes: 1 addition & 1 deletion quranref/scripts/text_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def import_text(language, text_name, filename):
log.info("Done importing!")


def main(argv=sys.argv): # pylint: disable=W0102
def text_import_main(argv): # pylint: disable=W0102
if len(argv) != 5:
usage(argv)

Expand Down

0 comments on commit df8c63f

Please sign in to comment.