| Conditions | 5 |
| Total Lines | 57 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | from argparse import ArgumentParser, Namespace |
||
| 131 | def create_article( |
||
| 132 | args: Namespace, |
||
| 133 | parameters_for_opening_edit: dict, |
||
| 134 | quiz_title: str, |
||
| 135 | quiz_wikitext: str, |
||
| 136 | wiki_domain: str, |
||
| 137 | ) -> None: |
||
| 138 | if args.new: |
||
| 139 | parameters_for_opening_edit_with_paste = parameters_for_opening_edit.copy() |
||
| 140 | parameters_for_opening_edit_with_paste.update( |
||
| 141 | { |
||
| 142 | "preload": "Sablon:Előbetöltés", |
||
| 143 | "preloadparams[]": quiz_wikitext, |
||
| 144 | } |
||
| 145 | ) |
||
| 146 | parameters_for_opening_edit_with_paste["summary"] = ( |
||
| 147 | parameters_for_opening_edit_with_paste["summary"].replace( |
||
| 148 | "bővítése", "létrehozása" |
||
| 149 | ) |
||
| 150 | ) |
||
| 151 | url = f"{wiki_domain}/wiki/{quiz_title}?{urlencode(parameters_for_opening_edit_with_paste)}" |
||
| 152 | if len(url) >= 2048: |
||
| 153 | logging.getLogger(__name__).warning( |
||
| 154 | "I can't create the article automatically " |
||
| 155 | "because the URL would be too long for some browsers (or the server)." |
||
| 156 | ) |
||
| 157 | if args.verbose: |
||
| 158 | pyperclip.copy(url) |
||
| 159 | print( |
||
| 160 | "This URL has been copied to the clipboard! " |
||
| 161 | "It will be overwritten but you may recall it later if you use an app like Pastebot." |
||
| 162 | ) |
||
| 163 | wait_for_pastebot_to_recognize_copy() |
||
| 164 | parameters_for_opening_edit["summary"] = parameters_for_opening_edit[ |
||
| 165 | "summary" |
||
| 166 | ].replace("bővítése", "létrehozása") |
||
| 167 | else: |
||
| 168 | pyperclip.copy(quiz_wikitext) |
||
| 169 | print( |
||
| 170 | "The wikitext of the quiz has been copied to the clipboard! " |
||
| 171 | "This will be overwritten but you may recall it later if you use an app like Pastebot." |
||
| 172 | ) |
||
| 173 | wait_for_pastebot_to_recognize_copy() |
||
| 174 | if args.verbose: |
||
| 175 | pyperclip.copy(url) |
||
| 176 | print("The URL has been copied to the clipboard!") |
||
| 177 | webbrowser.open_new_tab(url) |
||
| 178 | print( |
||
| 179 | "The edit page of the new quiz article has been opened in your browser with the wikitext pre-filled!" |
||
| 180 | ) |
||
| 181 | return |
||
| 182 | pyperclip.copy(quiz_wikitext) |
||
| 183 | print("The wikitext of the quiz has been copied to the clipboard!") |
||
| 184 | url = f"{wiki_domain}/wiki/{quiz_title}?{urlencode(parameters_for_opening_edit)}" |
||
| 185 | webbrowser.open_new_tab(url) |
||
| 186 | print( |
||
| 187 | "The edit page of the quiz article has been opened in your browser! Please paste the wikitext there manually." |
||
| 188 | ) |
||
| 199 |