💡 Handle Captcha Alone

This commit is contained in:
Mylloon 2021-08-31 09:04:55 +02:00
parent 370c0a83a2
commit 566747efc3
6 changed files with 69 additions and 3 deletions

View file

@ -39,4 +39,5 @@ dependencies {
// implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.5.30'
implementation 'com.github.kittinunf.fuel:fuel:2.3.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1'
implementation 'com.google.code.gson:gson:2.8.6'
}

View file

@ -0,0 +1,46 @@
{
"Which of the following is not a musical instrument? Metronome, violin, banjo, drum.": "Metronome",
"Which of the following is not a cheese? Mozzarella, Cipollina, Brie.": "Cipollina",
"Which of the following cannot be found in the desert? Camel/Bear/Scorpion.": "Bear",
"Which of the following has ancient architecture? Boston, Jerusalem, Seattle.": "Jerusalem",
"Which of the following is not a planet? Mars, Jupiter, Your Mom.": "Your Mom",
"Which of the following is not known for great wine? France, Belgium, Italy.": "Belgium",
"Which of the following is not an ancient civilization? Germany, China, Greece.": "Germany",
"Which of the following is not a flower? Lotus, Rose, Maple.": "Maple",
"Which of the following is not in the US? Beijing, New York City, San Francisco.": "Beijing",
"Who of the following is not an author? Conan Doyle, Hercule Poirot, Agatha Christie.": "Hercule Poirot",
"Which of the following is not a type of meat? Mutton, Beef, Tofu.": "Tofu",
"Who of the following never drove a car? Isaac Newton, Angelina Jolie, The Terminator.": "Isaac Newton",
"Which of the following experiences cold weather? Miami, Moscow, Cairo.": "Moscow",
"Which of the following is not in Europe? Miami, Rome, Barcelona.": "Miami",
"Which of the following has nice beaches? Moscow, Helsinki, Miami.": "Miami",
"Which of the following experiences cold weather? Madagascar, Helsinki, Buenos Aires.": "Helsinki",
"Which of the following has a high alcoholic content? Whiskey, Beer, Wine.": "Whiskey",
"Which of the following is not a whale? Narwhal, Humpback, Your Mom.": "Your Mom",
"Which of the following is not a planet? Hermes, Mercury, Saturn.": "Hermes",
"Who of the following is not a composer? Chopin, Beethoven, Bach, Moriarty.": "Moriarty",
"Which of the following is not a European capital? Paris, Berlin, Washington.": "Washington",
"Who of the following probably never rode in a car? Churchill, Ramses II, Obama.": "Ramses II",
"Which of the following is not a European capital? Paris, Tokyo, Rome.": "Tokyo",
"Which country in Europe is historically neutral in conflicts? Portugal, Switzerland, Austria.": "Switzerland",
"Which of the following countries remained neutral in World War II? Russia, Switzerland, France.": "Switzerland",
"Which one of the following is not in Europe? Paris/London/Chicago.": "Chicago",
"Which of the following is not an ancient civilization? Persia, Parthia, Poland.": "Poland",
"Which of the following languages is most different from English? German, Arabic, Swedish.": "Arabic",
"Which of the following is not made from grapes? Wine, beer, champagne.": "beer",
"Which of the following is not a religion? Judaism, Christianity, Narcissism.": "Narcissism",
"Who of the following has not been prime minister of Great Britain? Merkel, Cameron, Thatcher.": "Merkel",
"Which of the following is not an ancient civilization? Egypt, Inca, Germany.": "Germany",
"Which of the following is an ancient civilization? Spain, Persia, Sweden.": "Persia",
"Which of the following is not an ancient civilization? France, China, Carthage.": "France",
"Which of the following is not a capital of a country? Barcelona, Kyiv, London.": "Barcelona",
"Who of the following never drove a car? Jesus, Bush, Austin Powers.": "Jesus",
"Which of the following is not a fish? Salmon, Shark, Dolphin.": "Shark",
"Which of the following is not a tree? Cranberry, Apple, Orange.": "Cranberry",
"Which of the following is not a cheese? Camembert, Cumberbatch, Brie.": "Cumberbatch",
"Who of the following is not a painter? Dali, Picasso, that cousin who went to art school, Rembrandt.": "that cousin who went to art school",
"Which of the following is not an ancient civilization? Maya, Sumeria, Portugal.": "Portugal",
"Which of the following is not a real animal? Comodo Dragon, Salamander, Unicorn.": "Unicorn",
"Which of the following is a dish? Hamburg, Violin, Sausage": "Sausage",
"Which of the following isn't a colonial power? Portugal, Spain, Switzerland." : "Switzerland"
}

View file

@ -22,6 +22,8 @@ import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import kotlinx.coroutines.runBlocking
import java.util.*
@ -236,6 +238,15 @@ class MainActivity : AppCompatActivity() {
if (returns != null) { // if job is needed
if (returns[0] == "errorNotConnected") loginPage()
if (returns[0] == "loginAttemptsExceeded") {
if (returns[1] == "null") callScrapper(user, password, app)
val registeredAnswered: Map<String, String> = Gson().fromJson(
applicationContext.assets.open("captcha.json").bufferedReader()
.use { it.readText() },
object : TypeToken<Map<String, String>>() {}.type
)
for((key, value) in registeredAnswered){
if (returns[1] == key) return@runBlocking callScrapper(user, password, app, returns[2], value)
}
val builder: android.app.AlertDialog.Builder = android.app.AlertDialog.Builder(
instance)
builder.setTitle("Captcha")
@ -245,8 +256,10 @@ class MainActivity : AppCompatActivity() {
builder.setView(input)
builder.setPositiveButton(R.string.validate) { _, _ -> callScrapper(user, password, app, returns[2], input.text.toString()) }
builder.setNeutralButton(R.string.cancel) { dialog, _ -> dialog.cancel() }
builder.show()
Toast.makeText(applicationContext(), "${getString(R.string.connectionFailed)}\n${getString(R.string.credentialsDeleted)}.",
Toast.LENGTH_LONG).show()
}
}
}

View file

@ -66,9 +66,11 @@ class Scraper(
private fun error(htmlPage: String): MutableList<String>? {
var message = ""
var array: MutableList<String>? = null
var lengthTime = Toast.LENGTH_LONG
if (errorNotConnected in htmlPage) {
if (loginAttemptsExceeded in htmlPage) {
message = applicationContext().getString(R.string.loginAttemptsExceeded)
message = "${applicationContext().getString(R.string.knownCaptcha)}..."
lengthTime = Toast.LENGTH_LONG
val qaConfirmID = "(?<=qa_confirm_id\" value=\")(.{32})".toRegex().find(htmlPage)?.value
var answer = "(?<=answer\">)(.*)</l".toRegex().find(htmlPage)?.value
answer = answer?.dropLast(3)
@ -80,7 +82,7 @@ class Scraper(
}
}
println(errorFormat(message = message))
Toast.makeText(applicationContext(), message, Toast.LENGTH_LONG)
Toast.makeText(applicationContext(), message, lengthTime)
.show()
return array
@ -119,6 +121,8 @@ class Scraper(
private fun parse(htmlPage: String): MutableList<String>? {
if (debug) println("Fetching results for $app...")
Toast.makeText(applicationContext(), "Fetching results for $app...", Toast.LENGTH_SHORT)
.show()
// println(htmlPage)
return null
}

View file

@ -22,4 +22,5 @@
<string name="credentialsDeleted">Vos identifiants ont été supprimées</string>
<string name="loginAttemptsExceeded">Vous avez dépassé le nombre maximum de tentatives de connexion, veuillez compléter les captchas</string>
<string name="notConnected">Vous n\'êtes pas connecté, redirection vers la page de connexion</string>
<string name="knownCaptcha">Résolution des captchas</string>
</resources>

View file

@ -29,4 +29,5 @@
<string name="connectionFailed">Login failed, change your credentials</string>
<string name="credentialsDeleted">Your credentials have been deleted</string>
<string name="loginAttemptsExceeded">You have exceeded the maximum number of connection attempts, please complete captchas</string>
<string name="knownCaptcha">Resolving captchas</string>
</resources>