Test.kt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import com.alibaba.fastjson.JSONObject
  2. import com.google.gson.JsonObject
  3. import net.mamoe.mirai.console.plugins.*
  4. import net.mamoe.mirai.utils.cryptor.contentToString
  5. import org.jsoup.Connection
  6. import org.jsoup.Jsoup
  7. import java.io.File
  8. import kotlin.concurrent.thread
  9. object Data {
  10. val section = (File(System.getProperty("user.dir") + "/setu.yml")).loadAsConfig()
  11. val abstract = section.getStringList("abstract").toMutableList()
  12. val R18 = section.getConfigSectionList("R18").toMutableList()
  13. val normal = section.getConfigSectionList("normal").toMutableList()
  14. fun init() {
  15. section.setIfAbsent("abstract", mutableListOf<String>())
  16. section.setIfAbsent("R18", mutableListOf<ConfigSection>())
  17. section.setIfAbsent("Normal", mutableListOf<ConfigSection>())
  18. }
  19. fun save() {
  20. section["abstract"] = abstract
  21. section["R18"] = R18
  22. section["normal"] = normal
  23. section.save()
  24. }
  25. }
  26. fun main() {
  27. val abstract_file = (File(System.getProperty("user.dir") + "/abstractSetu.yml")).loadAsConfig()
  28. abstract_file.setIfAbsent("R18", mutableListOf<ConfigSection>())
  29. abstract_file.setIfAbsent("normal", mutableListOf<ConfigSection>())
  30. val r18 = abstract_file.getConfigSectionList("R18").toMutableList()
  31. val normal = abstract_file.getConfigSectionList("normal").toMutableList()
  32. Data.R18.forEach {
  33. val forbid = with(it.getString("tags")) {
  34. this.contains("初音ミク") || this.contains("VOCALOID") || this.contains("Miku")
  35. ||
  36. this.contains("东方") || this.contains("東方")
  37. }
  38. if (forbid) {
  39. println("过滤掉了一张图")
  40. } else {
  41. r18.add(
  42. ConfigSectionImpl().apply {
  43. this["pid"] = it["pid"]!!
  44. this["author"] = it["author"]!!
  45. this["uid"] = it["uid"]!!
  46. this["tags"] = it["tags"]!!
  47. this["url"] = it["url"]!!
  48. }
  49. )
  50. }
  51. }
  52. Data.normal.forEach {
  53. val forbid = with(it.getString("tags")) {
  54. this.contains("初音ミク") || this.contains("VOCALOID") || this.contains("Miku")
  55. ||
  56. this.contains("东方") || this.contains("東方")
  57. }
  58. if (forbid) {
  59. println("过滤掉了一张图")
  60. } else {
  61. normal.add(
  62. ConfigSectionImpl().apply {
  63. this["pid"] = it["pid"]!!
  64. this["author"] = it["author"]!!
  65. this["uid"] = it["uid"]!!
  66. this["tags"] = it["tags"]!!
  67. this["url"] = it["url"]!!
  68. }
  69. )
  70. }
  71. }
  72. abstract_file.set("R18", r18)
  73. abstract_file.set("normal", normal)
  74. abstract_file.save()
  75. /**
  76. Data.init()
  77. Runtime.getRuntime().addShutdownHook(thread(start = false) {
  78. Data.save()
  79. })
  80. while (true){
  81. try {
  82. val val0 = JSONObject.parseObject(Jsoup
  83. .connect("https://api.lolicon.app/setu/")
  84. .ignoreContentType(true)
  85. .method(Connection.Method.GET)
  86. .data("r18","1")
  87. .data("num","10")
  88. .execute().body())
  89. val val1 = val0.getJSONArray("data")
  90. for(index in 0 until val1.size - 1){
  91. val content = val1.getJSONObject(index)
  92. val pid = content.getString("pid")
  93. if(Data.abstract.contains(pid)){
  94. println("获取到了一张重复图$pid")
  95. continue
  96. }
  97. val configSection = ConfigSectionImpl()
  98. val isR18 = content.getBoolean("r18")
  99. configSection["author"] = content.getString("author")
  100. configSection["pid"] = pid
  101. configSection["uid"] = content.getInteger("uid")
  102. configSection["width"] = content.getInteger("width")
  103. configSection["height"] = content.getInteger("height")
  104. configSection["tags"] = content.getJSONArray("tags").map {
  105. it.toString()
  106. }.joinToString(",")
  107. configSection["url"] = content.getString("url")
  108. if(isR18){
  109. Data.R18.add(configSection)
  110. print("获取到了一张R18")
  111. }else{
  112. Data.normal.add(configSection)
  113. print("获取到了一张Normal")
  114. }
  115. Data.abstract.add(pid)
  116. println(configSection.contentToString())
  117. }
  118. }catch (e:Exception){
  119. println(e.message)
  120. }
  121. Data.save()
  122. println("SAVED")
  123. Thread.sleep(1000)
  124. }
  125. */
  126. }