Parsers
extract_info(context, pkg_dict, template_length, tokens)
¶
Creates a simplified dictionary for use in a tweet string template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context |
The current context. |
required | |
pkg_dict |
The package information to be simplified. |
required | |
template_length |
The length of the text in the template (without any of the tokens). |
required | |
tokens |
A list of token names in the template (extracted via regex). |
required |
Returns:
| Type | Description |
|---|---|
|
dict |
Source code in ckanext/twitter/lib/parsers.py
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 64 65 | |
generate_tweet(context, pkg_id, is_new, force_truncate=True)
¶
Generates a standard tweet based on template values in the config. Does not post the tweet; just generates and returns the text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context |
The current context. |
required | |
pkg_id |
The ID of the package to tweet about. |
required | |
is_new |
True if the package has only just been created or given its first resource, False if it's being updated. |
required | |
force_truncate |
If True, enforces an extra check at the end to ensure the text is below 140 characters. This should not be necessary as other methods account for this, but this is an optional final check. |
True
|
Returns:
| Type | Description |
|---|---|
|
str |
Source code in ckanext/twitter/lib/parsers.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
get_number_records(context, pkg_id)
¶
Counts the total number of records associated with a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context |
The current context. |
required | |
pkg_id |
The package ID. |
required |
Returns:
| Type | Description |
|---|---|
|
int |
Source code in ckanext/twitter/lib/parsers.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
truncate_author(author)
¶
Shortens the author field using regular expressions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
author |
The full author string. |
required |
Returns:
| Type | Description |
|---|---|
|
str |
Source code in ckanext/twitter/lib/parsers.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
truncate_field(value, char_limit)
¶
Shortens the given value to a length equal to or less than the character limit and appends a continuation marker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
The value to be truncated. |
required | |
char_limit |
The maximum number of characters in the output string. |
required |
Returns:
| Type | Description |
|---|---|
|
str |
Source code in ckanext/twitter/lib/parsers.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |