Commit 24cd6f49 authored by sim's avatar sim

[FIX] Django settings import

parent b8d171bd
......@@ -13,7 +13,8 @@ django.setup()
# ...to be able to import gargantext.
from gargantext import settings, models
from django.conf import settings
from gargantext import models
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
......
......@@ -37,7 +37,7 @@ import re
import importlib
from gargantext.util.lists import *
from gargantext.util import datetime, convert_to_datetime
from .settings import BASE_DIR
from django.conf import settings
# types & models (nodes, lists, hyperdata, resource) ---------------------------------------------
LISTTYPES = {
......@@ -398,7 +398,7 @@ DEFAULT_CSV_DELIM_GROUP = '|&|'
# Files ----------------------------------------------------------------
# uploads/.gitignore prevents corpora indexing
# copora can be either a folder or symlink towards specific partition
UPLOAD_DIRECTORY = os.path.join(BASE_DIR, 'uploads/corpora')
UPLOAD_DIRECTORY = os.path.join(settings.BASE_DIR, 'uploads/corpora')
UPLOAD_LIMIT = 1024 * 1024 * 1024
DOWNLOAD_DIRECTORY = UPLOAD_DIRECTORY
......
......@@ -12,7 +12,7 @@ import random
import urllib.parse as uparse
from lxml import etree
from gargantext.settings import API_TOKENS
from django.conf import settings
from ._Crawler import Crawler
from gargantext.util.timeit_damnit import timing
......@@ -21,7 +21,7 @@ from gargantext.util.timeit_damnit import timing
class CernCrawler(Crawler):
'''CERN SCOAP3 API Interaction'''
def __init__(self):
API = API_TOKENS["CERN"]
API = settings.API_TOKENS["CERN"]
self.apikey = API["APIKEY"].encode("utf-8")
self.secret = bytearray(API["APISECRET"].encode("utf-8"))
self.BASE_URL = u"http://api.scoap3.org/search?"
......@@ -96,12 +96,12 @@ class CernCrawler(Crawler):
print(self.results_nb, "res")
#self.generate_urls()
return(self.ids)
def generate_urls(self):
''' generate raw urls of ONE record'''
self.urls = ["http://repo.scoap3.org/record/%i/export/xm?ln=en" %rid for rid in self.ids]
return self.urls
def fetch_records(self, ids):
''' for NEXT time'''
raise NotImplementedError
......
......@@ -8,21 +8,21 @@
from ._Crawler import *
import json
from gargantext.settings import API_TOKENS
from django.conf import settings
from gargantext.constants import UPLOAD_DIRECTORY
from math import trunc
from gargantext.util.files import save
class MultivacCrawler(Crawler):
''' Multivac API CLIENT'''
def __init__(self):
self.apikey = API_TOKENS["MULTIVAC"]
self.apikey = settings.API_TOKENS["MULTIVAC"]
# Main EndPoints
self.BASE_URL = "https://api.iscpif.fr/v2"
self.API_URL = "pvt/economy/repec/search"
# Final EndPoints
# TODO : Change endpoint according type of database
self.URL = self.BASE_URL + "/" + self.API_URL
......@@ -37,23 +37,23 @@ class MultivacCrawler(Crawler):
querystring = { "q" : query
, "count" : count
, "from" : fromPage
, "api_key" : API_TOKENS["MULTIVAC"]["APIKEY"]
, "api_key" : settings.API_TOKENS["MULTIVAC"]["APIKEY"]
}
if lang is not None:
querystring["lang"] = lang
# Specify Headers
headers = { "cache-control" : "no-cache" }
# Do Request and get response
response = requests.request( "GET"
, self.URL
, headers = headers
, params = querystring
)
#print(querystring)
# Validation : 200 if ok else raise Value
if response.status_code == 200:
......@@ -64,27 +64,27 @@ class MultivacCrawler(Crawler):
return (json.loads(response.content.decode(charset)))
else:
raise ValueError(response.status_code, response.reason)
def scan_results(self, query):
'''
scan_results : Returns the number of results
Query String -> Int
'''
self.results_nb = 0
total = ( self._get(query)
.get("results", {})
.get("total" , 0)
)
self.results_nb = total
return self.results_nb
def download(self, query):
downloaded = False
self.status.append("fetching results")
corpus = []
......@@ -98,7 +98,7 @@ class MultivacCrawler(Crawler):
)
print("ERROR (scrap: Multivac d/l ): " , msg)
self.query_max = QUERY_SIZE_N_MAX
for page in range(1, trunc(self.query_max / 100) + 2):
print("Downloading page %s to %s results" % (page, paging))
docs = (self._get(query, fromPage=page, count=paging)
......@@ -114,5 +114,5 @@ class MultivacCrawler(Crawler):
, basedir=UPLOAD_DIRECTORY
)
downloaded = True
return downloaded
......@@ -13,7 +13,6 @@ import datetime
from os import path
import threading
from traceback import print_tb
#from gargantext.settings import MEDIA_ROOT, BASE_DIR
from ._Crawler import Crawler
import requests
from lxml import etree
......
import importlib
from django.conf import settings
from gargantext.constants import RESOURCETYPES
from gargantext.settings import DEBUG
#if DEBUG: print("Loading available Crawlers")
#if settings.DEBUG: print("Loading available Crawlers")
base_parser = "gargantext.util.crawlers"
for resource in RESOURCETYPES:
......@@ -14,7 +14,7 @@ for resource in RESOURCETYPES:
module = base_parser+".%s" %(filename)
importlib.import_module(module)
#if DEBUG: print("\t-", name)
#if settings.DEBUG: print("\t-", name)
except Exception as e:
print("Check constants.py RESOURCETYPES declaration %s \nCRAWLER %s is not available for %s" %(str(e), resource["crawler"], resource["name"]))
......
import subprocess
import re
from django.conf import settings
from .sparql import Service
from gargantext.settings import BOOL_TOOLS_PATH
#from sparql import Service
def bool2sparql(rawQuery, count=False, offset=None, limit=None):
"""
......@@ -13,7 +12,7 @@ def bool2sparql(rawQuery, count=False, offset=None, limit=None):
See: https://github.com/delanoe/bool2sparql
"""
query = re.sub("\"", "\'", rawQuery)
bashCommand = [BOOL_TOOLS_PATH + "/bool2sparql-exe","-q",query]
bashCommand = [settings.BOOL_TOOLS_PATH + "/bool2sparql-exe","-q",query]
if count is True :
bashCommand.append("-c")
......@@ -21,7 +20,7 @@ def bool2sparql(rawQuery, count=False, offset=None, limit=None):
if offset is not None :
for command in ["--offset", str(offset)] :
bashCommand.append(command)
if limit is not None :
for command in ["--limit", str(limit)] :
bashCommand.append(command)
......@@ -29,7 +28,7 @@ def bool2sparql(rawQuery, count=False, offset=None, limit=None):
process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE)
output, error = process.communicate()
if error is not None :
raise(error)
else :
......@@ -43,7 +42,7 @@ def isidore(query, count=False, offset=None, limit=None):
"""
query = bool2sparql(query, count=count, offset=offset, limit=limit)
go = Service("https://www.rechercheisidore.fr/sparql/", "utf-8", "GET")
results = go.query(query)
......@@ -52,10 +51,10 @@ def isidore(query, count=False, offset=None, limit=None):
doc = dict()
doc_values = dict()
doc["url"], doc["title"], doc["date"], doc["abstract"], doc["source"] = r
for k in doc.keys():
doc_values[k] = doc[k].value
yield(doc_values)
......
import os
from gargantext.settings import MEDIA_ROOT
from datetime import MINYEAR
from dateutil.parser import parse as parse_datetime_flexible
from django.utils.dateparse import parse_datetime
......
from gargantext import settings
from django.conf import settings
from gargantext.util.json import json_dumps
......
......@@ -6,7 +6,7 @@ from django import forms
from urllib.parse import quote_plus as urlencode
from gargantext import settings
from django.conf import settings
from sqlalchemy.orm.exc import DetachedInstanceError
from traceback import print_tb
......
import importlib
from gargantext.constants import RESOURCETYPES
from gargantext.settings import DEBUG
if DEBUG:
from django.conf import settings
if settings.DEBUG:
print("Loading available PARSERS:")
base_parser = "gargantext.util.parsers"
for resource in RESOURCETYPES:
......@@ -12,6 +12,6 @@ for resource in RESOURCETYPES:
module = base_parser+".%s" %(fname.upper())
#parser module is has shown in constants
parser = importlib.import_module(module)
if DEBUG:
if settings.DEBUG:
print("\t-", resource["parser"])
getattr(parser,resource["parser"])
......@@ -42,8 +42,8 @@ def scheduled_celery(func):
return go
from gargantext.settings import DEBUG
if DEBUG:
from django.conf import settings
if settings.DEBUG:
# scheduled = scheduled_now
scheduled = scheduled_thread
else:
......
......@@ -2,7 +2,7 @@
from gargantext.models.users import User
from gargantext.util.db import session
from django.core.mail import send_mail
from gargantext.settings import BASE_URL
from django.conf import settings
......@@ -65,7 +65,7 @@ drafts = {
def notification(corpus, draft, subject='Update'):
user = session.query(User).filter(User.id == corpus.user_id).first()
message = draft % (corpus.name, BASE_URL, corpus.parent_id, corpus.id)
message = draft % (corpus.name, settings.BASE_URL, corpus.parent_id, corpus.id)
if user.email != "" :
send_mail('[Gargantext] %s' % subject
......
from gargantext.settings import DEBUG
from django.conf import settings
from .parsing import parse
from .ngrams_extraction import extract_ngrams
from .hyperdata_indexing import index_hyperdata
......@@ -176,7 +176,7 @@ def parse_extract_indexhyperdata(corpus):
session.commit()
if DEBUG is False:
if settings.DEBUG is False:
print('CORPUS #%d: [%s] FINISHED Sending email notification' % (corpus.id, t()))
notify_owner(corpus)
......@@ -299,7 +299,7 @@ def recount(corpus_id):
corpus.save_hyperdata()
session.commit()
if not DEBUG:
if not settings.DEBUG:
print('RECOUNT #%d: [%s] FINISHED Sending email notification' % (corpus.id, t()))
notify_recount(corpus)
......
......@@ -2,7 +2,6 @@
COOCS
(this is the full SQL version, should be more reliable on outerjoin)
"""
from gargantext import settings
from sqlalchemy import exc
from gargantext.util.lists import WeightedMatrix
from gargantext.util.db import get_engine
......@@ -112,7 +111,7 @@ def compute_coocs( corpus,
-- GROUP BY ngA, ngB
)
"""
# 3) taking the cooccurrences of ngram x2
ngram_filter_A_sql += """
-- STEP 1: X axis of the matrix
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment