Commit 81b1aba8 authored by sim's avatar sim

[FIX] Django settings import

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