diff options
author | James Taylor <user234683@users.noreply.github.com> | 2018-11-10 21:13:49 -0800 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2018-11-10 21:13:49 -0800 |
commit | 409fea01971c13eae62109f1b8afc01b94960beb (patch) | |
tree | e6ed412333b805ad72603d5b7f2f6824134ab0ce /youtube/account_functions.py | |
parent | 717bf210937c757595624348db9389969be9654f (diff) | |
download | yt-local-409fea01971c13eae62109f1b8afc01b94960beb.tar.lz yt-local-409fea01971c13eae62109f1b8afc01b94960beb.tar.xz yt-local-409fea01971c13eae62109f1b8afc01b94960beb.zip |
Use post/redirect/get method to prevent form resubmission for comments
Diffstat (limited to 'youtube/account_functions.py')
-rw-r--r-- | youtube/account_functions.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/youtube/account_functions.py b/youtube/account_functions.py index 0c7973b..22346e4 100644 --- a/youtube/account_functions.py +++ b/youtube/account_functions.py @@ -104,11 +104,11 @@ def delete_comment(video_id, comment_id, author_id, session_token, cookie): content = response.read() xsrf_token_regex = re.compile(r'''XSRF_TOKEN"\s*:\s*"([\w-]*(?:=|%3D){0,2})"''') -def post_comment(query_string, fields): +def post_comment(parameters, fields): with open(os.path.join(settings.data_dir, 'cookie.txt'), 'r', encoding='utf-8') as f: cookie_data = f.read() - parameters = urllib.parse.parse_qs(query_string) + #parameters = urllib.parse.parse_qs(query_string) try: video_id = fields['video_id'][0] except KeyError: @@ -129,7 +129,7 @@ def post_comment(query_string, fields): if 'parent_id' in parameters: code = _post_comment_reply(fields['comment_text'][0], parameters['video_id'][0], parameters['parent_id'][0], token, cookie_data) - try: + '''try: response = comments.get_comments_page(query_string) except socket.error as e: traceback.print_tb(e.__traceback__) @@ -137,10 +137,11 @@ def post_comment(query_string, fields): except Exception as e: traceback.print_tb(e.__traceback__) return b'Refreshing comment page yielded error 500 Internal Server Error.\nPost comment status code: ' + code.encode('ascii') - return response + return response''' else: code = _post_comment(fields['comment_text'][0], fields['video_id'][0], token, cookie_data) - try: + + '''try: response = comments.get_comments_page('ctoken=' + comments.make_comment_ctoken(video_id, sort=1)) except socket.error as e: traceback.print_tb(e.__traceback__) @@ -148,8 +149,8 @@ def post_comment(query_string, fields): except Exception as e: traceback.print_tb(e.__traceback__) return b'Refreshing comment page yielded error 500 Internal Server Error.\nPost comment status code: ' + code.encode('ascii') - return response - + return response''' + return code def get_post_comment_page(query_string): @@ -180,7 +181,7 @@ textarea{ ) else: comment_box = comments.comment_box_template.substitute( - form_action = common.URL_ORIGIN + '/comments?ctoken=' + comments.make_comment_ctoken(video_id, sort=1).replace("=", "%3D"), + form_action = common.URL_ORIGIN + '/post_comment', video_id_input = '''<input type="hidden" name="video_id" value="''' + video_id + '''">''', post_text = "Post comment", ) |