|
| 1 | +""" |
| 2 | +%2B = + |
| 3 | +%3D = = |
| 4 | +%2F = / |
| 5 | +
|
| 6 | +Symbolab: |
| 7 | +sin = /sin |
| 8 | +(=\left( |
| 9 | +)=\right) |
| 10 | +* = \cdot |
| 11 | +
|
| 12 | +
|
| 13 | +\=\frac{num}{denom} |
| 14 | +
|
| 15 | +
|
| 16 | +""" |
| 17 | + |
| 18 | +from bs4 import BeautifulSoup |
| 19 | +from selenium import webdriver |
| 20 | + |
| 21 | +GETINPUT = True |
| 22 | + |
| 23 | +uinput = "1+1" |
| 24 | + |
| 25 | +if(GETINPUT == True): |
| 26 | + uinput = input("Enter Input: ") |
| 27 | + |
| 28 | + |
| 29 | +runWOLFRAM = True |
| 30 | +runCYMATH = True |
| 31 | +runSYMBOLAB = True |
| 32 | + |
| 33 | + |
| 34 | +browser = webdriver.PhantomJS( |
| 35 | + executable_path='C:\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe') |
| 36 | + |
| 37 | + |
| 38 | +def formaturlexpr(expr, urlbase, site): |
| 39 | + # sin(3*x)%2B4%3D4-5*pi |
| 40 | + if (site == "wolfram" or site == "cymath"): |
| 41 | + eu1 = expr.replace('+', '%2B') |
| 42 | + eu2 = eu1.replace('=', '%3D') |
| 43 | + eu3 = eu2.replace('/', '%2F') |
| 44 | + endurl = eu3 |
| 45 | + finalurl = urlbase + endurl |
| 46 | + # print(finalurl) |
| 47 | + return finalurl |
| 48 | + elif (site == "symbolab"): |
| 49 | + eu1 = expr.replace('+', '%2B') |
| 50 | + eu2 = eu1.replace('=', '%3D') |
| 51 | + eu3 = eu2.replace('/', '%2F') |
| 52 | + eu4 = eu3.replace('sin', '/sin') |
| 53 | + eu5 = eu4.replace('(', '\\left(') |
| 54 | + eu6 = eu5.replace(')', '\\right)') |
| 55 | + eu7 = eu6.replace('*', '\\cdot') |
| 56 | + endurl = eu7 |
| 57 | + finalurl = urlbase + endurl |
| 58 | + # print(finalurl) |
| 59 | + return finalurl |
| 60 | + |
| 61 | + |
| 62 | +site = "https://www.wolframalpha.com/input/?i=" |
| 63 | + |
| 64 | + |
| 65 | +def WolframFunction(): |
| 66 | + sitedemo = "https://www.wolframalpha.com/input/?i=sin(x)%3D24" |
| 67 | + site = formaturlexpr( |
| 68 | + uinput, "https://www.wolframalpha.com/input/?i=", "wolfram") |
| 69 | + |
| 70 | + browser.set_window_size(1120, 550) |
| 71 | + browser.get(site) |
| 72 | + browser.save_screenshot('wolframscreenshot.png') |
| 73 | + |
| 74 | + html = browser.page_source |
| 75 | + soup = BeautifulSoup(html, 'html.parser') |
| 76 | + |
| 77 | + SymbolicSolution = soup.find(id="SymbolicSolution") |
| 78 | + imglist = SymbolicSolution.find_all( |
| 79 | + 'img', class_='ng-isolate-scope', alt=True) |
| 80 | + |
| 81 | + print("WOLFRAMALPHA") |
| 82 | + |
| 83 | + for item in imglist: |
| 84 | + # print(item.get_text()) |
| 85 | + print(item['alt']) |
| 86 | + |
| 87 | + |
| 88 | +def CymathFunction(): |
| 89 | + sitedemo = "https://www.cymath.com/answer?q=sin(x)%3D24" |
| 90 | + site = formaturlexpr(uinput, "https://www.cymath.com/answer?q=", "cymath") |
| 91 | + |
| 92 | + browser.set_window_size(1120, 550) |
| 93 | + browser.get(site) |
| 94 | + browser.save_screenshot('cymathscreenshot.png') |
| 95 | + |
| 96 | + html = browser.page_source |
| 97 | + soup = BeautifulSoup(html, 'html.parser') |
| 98 | + |
| 99 | + stepsdivlist = soup.find_all(id="steps_div") |
| 100 | + itnlist = soup.find_all(class_='itn') |
| 101 | + katexlist = soup.find_all(class_='katex') |
| 102 | + listmord = soup.find_all(class_='mord mathrm') |
| 103 | + sollist = soup.findChildren(class_='base textstyle uncramped') |
| 104 | + hiddenanswers = soup.find(id="answer") |
| 105 | + |
| 106 | + print("CYMATH") |
| 107 | + |
| 108 | + hiddenanswertext = hiddenanswers.get_text() |
| 109 | + # print(hiddenanswertext) |
| 110 | + hat1 = hiddenanswertext.replace('),sequence(', ' & ') |
| 111 | + hat2 = hat1.replace('sequence(', ' ') |
| 112 | + hat3 = hat2[:-1] |
| 113 | + hat4 = hat3.replace('PI', 'π') |
| 114 | + hiddenanswertext = hat4 |
| 115 | + print(hiddenanswertext) |
| 116 | + |
| 117 | + |
| 118 | +def SymbolabFunction(): |
| 119 | + sitedemo = "https://www.symbolab.com/solver/step-by-step/sin%5Cleft(x%5Cright)%3D24" |
| 120 | + site = "https://www.symbolab.com/solver/step-by-step/sin%5Cleft(x%5Cright)%3D24" |
| 121 | + |
| 122 | + browser.set_window_size(1120, 550) |
| 123 | + browser.get(site) |
| 124 | + browser.save_screenshot('symbolabscreenshot.png') |
| 125 | + |
| 126 | + html = browser.page_source |
| 127 | + soup = BeautifulSoup(html, 'html.parser') |
| 128 | + |
| 129 | + selectablelist = soup.find_all(class_='selectable') |
| 130 | + solutionslist = soup.find_all(class_='solution_step_list_item') |
| 131 | + |
| 132 | + # print(solutionsteplist) |
| 133 | + |
| 134 | + print("SYMBOLAB") |
| 135 | + |
| 136 | + for item in solutionslist: |
| 137 | + |
| 138 | + print(item.get_text()) |
| 139 | + |
| 140 | + |
| 141 | +if runWOLFRAM == True: |
| 142 | + try: |
| 143 | + WolframFunction() |
| 144 | + except: |
| 145 | + print("Wolfram gave up!") |
| 146 | + |
| 147 | +if runCYMATH == True: |
| 148 | + try: |
| 149 | + CymathFunction() |
| 150 | + except: |
| 151 | + print("Cymath gave up!") |
| 152 | + |
| 153 | +if runSYMBOLAB == True: |
| 154 | + try: |
| 155 | + SymbolabFunction() |
| 156 | + except: |
| 157 | + print("Symbolab gave up!") |
0 commit comments