.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.data.currencies.CurrenciesDB Class Reference

Public Member Functions

 __init__ (self)
 
 init (self)
 
 load (self)
 
 name_to_iso4217 (self, name)
 
 iso4217_to_name (self, iso4217, language)
 

Public Attributes

 cache = get_cache()
 

Static Public Attributes

str ctx_names = "data_currencies_names"
 
str ctx_iso4217 = "data_currencies_iso4217"
 
str json_file = pathlib.Path(__file__).parent / "currencies.json"
 

Detailed Description

Definition at line 14 of file currencies.py.

Constructor & Destructor Documentation

◆ __init__()

searx.data.currencies.CurrenciesDB.__init__ ( self)

Definition at line 22 of file currencies.py.

22 def __init__(self):
23 self.cache = get_cache()
24

Member Function Documentation

◆ init()

searx.data.currencies.CurrenciesDB.init ( self)

Definition at line 25 of file currencies.py.

25 def init(self):
26 if self.cache.properties("currencies loaded") != "OK":
27 self.load()
28 self.cache.properties.set("currencies loaded", "OK")
29 # F I X M E:
30 # do we need a maintenance .. rember: database is stored
31 # in /tmp and will be rebuild during the reboot anyway
32

References cache, and load().

Referenced by searx.sqlitedb.SQLiteAppl.connect(), searx.sqlitedb.SQLiteAppl.DB(), iso4217_to_name(), and name_to_iso4217().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ iso4217_to_name()

searx.data.currencies.CurrenciesDB.iso4217_to_name ( self,
iso4217,
language )

Definition at line 51 of file currencies.py.

51 def iso4217_to_name(self, iso4217, language):
52 self.init()
53
54 iso4217_languages: dict = self.cache.get(key=iso4217, default={}, ctx=self.ctx_iso4217)
55 return iso4217_languages.get(language, iso4217)

References cache, ctx_iso4217, searx.cache.ExpireCacheSQLite.init(), and init().

+ Here is the call graph for this function:

◆ load()

searx.data.currencies.CurrenciesDB.load ( self)

Definition at line 33 of file currencies.py.

33 def load(self):
34 log.debug("init searx.data.CURRENCIES")
35 with open(self.json_file, encoding="utf-8") as f:
36 data_dict = json.load(f)
37 for key, value in data_dict["names"].items():
38 self.cache.set(key=key, value=value, ctx=self.ctx_names, expire=None)
39 for key, value in data_dict["iso4217"].items():
40 self.cache.set(key=key, value=value, ctx=self.ctx_iso4217, expire=None)
41

References cache, ctx_iso4217, ctx_names, and json_file.

Referenced by init().

+ Here is the caller graph for this function:

◆ name_to_iso4217()

searx.data.currencies.CurrenciesDB.name_to_iso4217 ( self,
name )

Definition at line 42 of file currencies.py.

42 def name_to_iso4217(self, name):
43 self.init()
44
45 ret_val = self.cache.get(key=name, default=name, ctx=self.ctx_names)
46 if isinstance(ret_val, list):
47 # if more alternatives, use the last in the list
48 ret_val = ret_val[-1]
49 return ret_val
50

References cache, ctx_names, searx.cache.ExpireCacheSQLite.init(), and init().

+ Here is the call graph for this function:

Member Data Documentation

◆ cache

searx.data.currencies.CurrenciesDB.cache = get_cache()

Definition at line 23 of file currencies.py.

Referenced by init(), iso4217_to_name(), load(), and name_to_iso4217().

◆ ctx_iso4217

str searx.data.currencies.CurrenciesDB.ctx_iso4217 = "data_currencies_iso4217"
static

Definition at line 18 of file currencies.py.

Referenced by iso4217_to_name(), and load().

◆ ctx_names

str searx.data.currencies.CurrenciesDB.ctx_names = "data_currencies_names"
static

Definition at line 17 of file currencies.py.

Referenced by load(), and name_to_iso4217().

◆ json_file

searx.data.currencies.CurrenciesDB.json_file = pathlib.Path(__file__).parent / "currencies.json"
static

Definition at line 20 of file currencies.py.

Referenced by load().


The documentation for this class was generated from the following file: