Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

#!/usr/bin/python 

# -*- coding: utf-8 -*- 

''' 

Configuration for the monuments bot. 

 

''' 

import json 

import os 

 

 

def _get_config_dir(): 

return os.path.join( 

os.path.dirname(os.path.abspath(__file__)), 'monuments_config') 

 

 

def _read_config_from_file(config_file): 

with open(config_file, 'r', encoding='utf-8') as fp: 

return json.load(fp) 

 

 

def _read_country_config(config_file): 

data = _read_config_from_file(config_file) 

# Trick to convert back into tuples 

if type(data.get('primkey', None)) is list: 

data['primkey'] = tuple(data['primkey']) 

return data 

 

 

def get_countries(): 

countries = {} 

 

config_dir = _get_config_dir() 

for filename in os.listdir(config_dir): 

base, ext = os.path.splitext(filename) 

if ext != '.json': 

continue 

config_file = os.path.join(config_dir, filename) 

data = _read_country_config(config_file) 

key = (data['country'], data['lang']) 

countries[key] = data 

return countries 

 

 

def filtered_countries(respect_skip=True, skip_wd=False, skip_wlpa=False): 

""" 

A filtered country config iterator. 

 

@param respect_skip: filter out any dataset with "skip=True" 

@param skip_wd: filter out any dataset with "type='sparql'" 

@param skip_wlpa: filter out any dataset in the wlpa_all table 

""" 

for key, countryconfig in get_countries().items(): 

if respect_skip and countryconfig.get('skip'): 

continue 

elif skip_wd and (countryconfig.get('type') == 'sparql'): 

continue 

elif skip_wlpa and countryconfig.get('table', '').startswith('wlpa_'): 

continue 

else: 

yield key, countryconfig 

 

 

countries = get_countries()