Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. import com.google.auth.oauth2.GoogleCredentials
  2. import com.google.cloud.datastore.*
  3. import java.io.File
  4. import kotlin.random.Random
  5. import com.oracle.util.Checksums.update
  6. import com.google.cloud.datastore.TransactionExceptionHandler.build
  7. import com.google.gson.Gson
  8. import com.google.cloud.datastore.StructuredQuery.OrderBy
  9. import com.google.cloud.datastore.Query.newEntityQueryBuilder
  10. import com.google.cloud.datastore.TransactionExceptionHandler.build
  11.  
  12.  
  13. val names = listOf(
  14. "! *̣̣ ღ 𝓐𝓶𝓮𝔁𝔂 ღ *̣̣ 🐝",
  15. "! Afx",
  16. "! Alshame97",
  17. "! Christopher Freitas",
  18. "! ipkez",
  19. "! Neeko2lo (Rabbit)",
  20. "! Zhava",
  21. "! 🍜 GuyNoodle 🍜 !",
  22. "!!Makahaa!!",
  23. "! life sucks",
  24. "Ahnaris",
  25. "!Boogie",
  26. "!DARK LORD",
  27. "!Entheos",
  28. "!Fia",
  29. "!Kyle2Hype",
  30. "!Taki",
  31. "Dylo",
  32. "$ ✘‿✘ LLama",
  33. "!a ॐ",
  34. "The Cat!",
  35. "\$aku",
  36. "\$cott",
  37. "'** Sir_Guifred **'",
  38. "-3(",
  39. "!.!.rall.!.!",
  40. "-V-",
  41. "./unnamed",
  42. ".Ace.",
  43. ".bit",
  44. ".Bypass",
  45. ".Cowboy",
  46. ".Jura",
  47. "'Rikka",
  48. ".KayTV",
  49. ".Lucas.",
  50. ".ProudHeart",
  51. ".𝔗𝔯𝔞𝔦𝔫𝔢𝔯_🅱𝔯𝔢𝔫𝔡𝔞𝔫.",
  52. "009 Sound System",
  53. "07 Officer"
  54. )
  55.  
  56. fun main() {
  57. val gson = Gson()
  58.  
  59. val datastore = DatastoreOptions.newBuilder()
  60. .setProjectId("firestoredatastore-254209")
  61. .setCredentials(GoogleCredentials.fromStream(File("FirestoreDatastore-f4885100cfa7.json").inputStream()))
  62. .build()
  63. .service
  64.  
  65. val keyFactory = datastore.newKeyFactory().setKind("TestEntity")
  66. val key = keyFactory.setKind("TestEntity").newKey()
  67.  
  68. // Record a visit to the datastore, storing the IP and timestamp.
  69.  
  70. // names.parallelStream().forEach {
  71. // val newThing = Entity.newBuilder<IncompleteKey>(key)
  72. // .set("ip_addresses", "88.200.136.211")
  73. // .set("name", it)
  74. // .set("rnum", Random.nextLong())
  75. // .set("isDisabled", Random.nextBoolean()).build()
  76. // datastore.add(newThing)
  77. // }
  78.  
  79.  
  80. // println(timePar)
  81. // println(timesync)
  82.  
  83. val single = datastore[keyFactory.newKey(5409299698286592)]
  84.  
  85. val newSingle = Entity.newBuilder(single).set("name", "a new name").build()
  86. datastore.update(newSingle)
  87.  
  88. // Retrieve the last 10 visits from the datastore, ordered by timestamp.
  89. val query = Query.newEntityQueryBuilder()
  90. .setKind("TestEntity")
  91. .setFilter(
  92. StructuredQuery.CompositeFilter.and(
  93. StructuredQuery.PropertyFilter.eq("isDisabled", false),
  94. StructuredQuery.PropertyFilter.eq(
  95. "name",
  96. "\$aku"
  97. )
  98. )
  99. ).build()
  100.  
  101. val results = datastore.run(query).asSequence().map { it as Entity }.map {
  102. gson.toJson(it.properties)
  103. }.toList()
  104.  
  105. println(results)
  106.  
  107. // val newEntities = results.map {
  108. // Entity.newBuilder(it).set("rnum", 2).build()
  109. // }.toTypedArray()
  110.  
  111. // datastore.update(*newEntities)
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement