am_dot_com

CN 20230412

Apr 12th, 2023 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. // search.js
  2. window.onload = boot;
  3.  
  4. const ID_SEARCH_EXP = "id_search_exp",
  5. ID_CHECK_REDIRECT = "id_check_redirect",
  6. ID_BTN_SEARCH = "id_btn_search";
  7.  
  8. var oSearchExp, oCheckRedirect, oBtnSearch;
  9.  
  10. function id(pId) {
  11. return document.getElementById(pId);
  12. }//id
  13.  
  14. function boot(){
  15. oSearchExp = id(ID_SEARCH_EXP);
  16. oCheckRedirect = id(ID_CHECK_REDIRECT);
  17. oBtnSearch = id(ID_BTN_SEARCH);
  18.  
  19. var relevant=[
  20. oSearchExp,
  21. oCheckRedirect,
  22. oBtnSearch
  23. ]
  24.  
  25. for (r of relevant) {
  26. if (r == null) {
  27. window.alert("Relevant object NOT available. Aborting");
  28. return;
  29. }
  30. }//for
  31.  
  32. //window.alert("All relevant objects OK.");
  33.  
  34. oBtnSearch.onclick = go_search;
  35. }//boot
  36.  
  37. function go_search(){
  38. q = oSearchExp.value
  39. search_url =
  40. "https://www.google.com/search?q="+q;
  41.  
  42. bRedirect = oCheckRedirect.checked
  43. if(bRedirect){
  44. document.location.href = search_url;
  45. }
  46. else{
  47. window.alert("Not implemented");
  48. }
  49.  
  50. }//go_search
  51.  
  52. ***********************
  53.  
  54. <!DOCTYPE html>
  55. <html lang="en">
  56. <head>
  57. <meta charset="UTF-8">
  58. <title>My search app with memory</title>
  59. <!-- ok for local, not ok for web app
  60. script src="../static/search.js"
  61. -->
  62. <script src=
  63. "{{ url_for('static', filename='search.js') }}">
  64. </script>
  65. </head>
  66. <body>
  67. <form>
  68. <fieldset>
  69. <legend>What and how to search</legend>
  70. <label for="id_search_exp">
  71. Search expression:
  72. </label>
  73. <input id="id_search_exp"
  74. type="text"
  75. placeholder="search for something"
  76. size="32"
  77. name="name_search_exp">
  78. <br>
  79. <label for="id_check_redirect">
  80. Redirect to search engine raw results
  81. </label>
  82. <input id="id_check_redirect"
  83. name="name_check_redirect"
  84. type="checkbox"
  85. checked>
  86. <input type="button"
  87. id="id_btn_search"
  88. value="go search">
  89. </fieldset>
  90. </form>
  91. <!-- conditional zone for the NO redirect case -->
  92. </body>
  93. </html>
  94.  
  95. ******
  96.  
  97. # application.py
  98. # the filename MUST BE application.py
  99. # for easy AWS EBS deployment
  100.  
  101. from flask import Flask, \
  102. request, render_template, \
  103. redirect
  104.  
  105. application = Flask(__name__)
  106.  
  107. @application.route("/", methods=['GET', 'POST'])
  108. def root():
  109. return render_template(
  110. "search2.html"
  111. )
  112. # def root
  113.  
  114. def receive_user_data():
  115. bGET:bool = request.method=='GET'
  116. bPOST:bool = request.method=='POST'
  117.  
  118. user_data:dict = request.args if bGET \
  119. else request.form
  120.  
  121. # user_data
  122. # def receive_user_data
  123.  
  124. bCLI = __name__ == '__main__'
  125. if(bCLI):
  126. # caution: force IP and PORT only on local dev
  127. application.run(
  128. #host="0.0.0.0",
  129. #port=5000, # default port
  130. debug=True
  131. )
  132. # if
Advertisement
Add Comment
Please, Sign In to add comment