Cool! Programmers use Python to take you to the summit, python Conference
In January 3, 2018, Wang Sicong was forced to use his microblog to advertise an App that was born less than 10 days ago. "I will pay a prize every day and send it 0.1 million at tonight ". For him, Weibo on this day is not a birthday banquet, but a battlefield. One of Wang Sicong's Weibo posts opened the road to the popularity of the "National Q & A" APP.
For a time, the live video giants kept up with the pace of "President Wang", outside of "topping the Conference, inke's "cheese Superman", toutiao.com's "millions of heroes", and the "millions of battles" under the pepper live broadcast have made their debut, spreading millions of dollars in cash every day.
The top conference, cheese Superman, millions of heroes, and other knowledge quiz games are on fire. The prize amount has also increased from RMB 50 thousand, 0.1 million to 1 million and 1.01 million.
In order to be able to answer all 12 correct questions and divide the prize pool with such a large amount, contestants began to find ways to improve the accuracy of their answers.
As introduced by the program host, many respondents began to look for friends around them to answer questions in order to cover more types of knowledge points and increase the chance of customs clearance.
Various qq q & A groups were born, and everyone shared their correct answers in the group chat.
What you cannot guess is that there are plug-ins in the Q & A game!
In order to be able to answer all 12 correct questions and divide the prize pool with such a large amount, contestants began to find ways to improve the accuracy of their answers.
A programmer has designed a "Helper Program" to quickly search for answers.
This Python program can trim and recognize the text content (problems and options) in the image, then search for the number of times the keyword appears through Baidu, and finally display the statistical information. In this way, the answer provider can select the corresponding answer based on the statistical data, which greatly improves the accuracy of the answer.
So how should programmers play?
First, use WDA to obtain the screen. WDA is a set of iOS testing frameworks developed by Facebook. A few days ago, we saw that everyone was using the plug-in for "Hop-Hop", so we learned about it and found that it could also be used at the summit.
Then, crop sends the question location (may need to adapt to the mobile phone screen), then calls the open OCR interface to read the text, and finally calls the search engine to achieve the effect of the previous gif image. This environment is iOS + Mac, and it should be more convenient for Android.
In fact, the original idea was to automate the search + selection of all answers. The idea was to combine OCR questions and candidate answers to make them available to Baidu or Google for search, then, you can select the combination with the maximum number of results. After trying a few questions, I found that this is not the case. For example, in the figure above, "what is the storage of camels ?", Most people may think it is water, so the most frequent appearance is actually the wrong answer.
There are also two pain points:
The free OCR interface is called for a limited number of times, so you cannot identify screenshots all the time. You can only run the program when the question appears.
The official website is also a routine, and some problems cannot be searched. For example:
The code is attached:
# Python3import wdaimport ioimport urllib. parseimport webbrowserimport requestsimport timeimport base64from PIL import Imagec = wda. client () # Baidu OCR APIapi_key = ''api _ secret ='' token = ''while True: time. sleep (0.5) c.screenshot('1.png ') im = Image. open (". /1.png") region = im. crop (75,315,116 7, 789) # iPhone 7 P imgByteArr = io. bytesIO () region. save (imgByteArr, format = 'png ') image_data = imgByteA Rr. getvalue () base64_data = base64.b64encode (image_data) r = requests. post ('https: // token, params = {'Access _ token': token}, data = {'image': base64_data}) result = ''for I in r. json () ['words _ result']: result + = I ['word'] result = urllib. parse. quote (result) webbrowser. open ('https: // baidu.com/s? Wd = '+ result) break
(Code Source: https://livc.io/blog/204)
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.