Skip to content

Config helpers

twitter_disable_edit()

Checks for a disable_edit flag in the config.

If true, this prevents the user editing the tweet before it is posted.

Returns:

Type Description

boolean

Source code in ckanext/twitter/lib/config_helpers.py
81
82
83
84
85
86
87
88
89
def twitter_disable_edit():
    """
    Checks for a disable_edit flag in the config.

    If true, this prevents the
    user editing the tweet before it is posted.
    :return: boolean
    """
    return toolkit.config.get('ckanext.twitter.disable_edit', False)

twitter_get_credentials()

Retrieves twitter API key and secret from config file.

Returns:

Type Description

(key, secret)

Source code in ckanext/twitter/lib/config_helpers.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def twitter_get_credentials():
    """
    Retrieves twitter API key and secret from config file.

    :return: (key, secret)
    """
    consumer_key = toolkit.config.get(
        'ckanext.twitter.consumer_key', 'no-consumer-key-set'
    )
    consumer_secret = toolkit.config.get(
        'ckanext.twitter.consumer_secret', 'no-consumer-secret-set'
    )
    token_key = toolkit.config.get('ckanext.twitter.token_key', 'no-token-key-set')
    token_secret = toolkit.config.get(
        'ckanext.twitter.token_secret', 'no-token-secret-set'
    )
    return consumer_key, consumer_secret, token_key, token_secret

twitter_hours_between_tweets()

For calculating the 'rest period' between subsequent tweets about the same dataset.

Returns:

Type Description

int

Source code in ckanext/twitter/lib/config_helpers.py
40
41
42
43
44
45
46
def twitter_hours_between_tweets():
    """
    For calculating the 'rest period' between subsequent tweets about the same dataset.

    :return: int
    """
    return toolkit.config.get('ckanext.twitter.hours_between_tweets', 24)

twitter_is_debug()

Checks debug flags in the config - the plugin-specific flag can override the global debug flag.

Returns:

Type Description

boolean

Source code in ckanext/twitter/lib/config_helpers.py
29
30
31
32
33
34
35
36
37
def twitter_is_debug():
    '''
    Checks debug flags in the config - the plugin-specific flag can override
    the global debug flag.
    :return: boolean
    '''
    return toolkit.config.get(
        'ckanext.twitter.debug', toolkit.config.get('debug', False)
    )

twitter_new_format()

Gets the string defining the format of the tweet that will be posted for new datasets.

Returns:

Type Description

string with replaceable jinja2 tags

Source code in ckanext/twitter/lib/config_helpers.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def twitter_new_format():
    """
    Gets the string defining the format of the tweet that will be posted for new
    datasets.

    :return: string with replaceable jinja2 tags
    """
    return toolkit.config.get(
        'ckanext.twitter.new',
        'New dataset: "{{ title }}" by {{ author }} ({'
        '%- if records != 0 -%} {{ records }} records {'
        '%- else -%} {{ resources }} resource {%- endif '
        '-%}).',
    )

twitter_updated_format()

Gets the string defining the format of the tweet that will be posted for updated.

Returns:

Type Description

string with replaceable jinja2 tags

Source code in ckanext/twitter/lib/config_helpers.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def twitter_updated_format():
    """
    Gets the string defining the format of the tweet that will be posted for updated.

    :return: string with replaceable jinja2 tags
    """
    return toolkit.config.get(
        'ckanext.twitter.updated',
        'Updated dataset: "{{ title }}" by {{ author }} '
        '({%- if records != 0 -%} {{ records }} records '
        '{%- elif resources == 1 -%} {{ resources }} '
        'resource {%- else -%} {{ resources }} '
        'resources {%- endif -%}).',
    )