-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add in vlog date calculations for volume 2
- Loading branch information
1 parent
dd539e6
commit 80a0ba2
Showing
5 changed files
with
67 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ | |
.externalNativeBuild | ||
.cxx | ||
local.properties | ||
*.jar | ||
*.jar | ||
app/bin/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 54 additions & 33 deletions
87
HaveAMagicalDay/app/src/main/kotlin/com/michaeltchuang/cron/App.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,63 @@ | ||
package com.michaeltchuang.cron | ||
|
||
import com.algorand.algosdk.account.Account | ||
import com.algorand.algosdk.builder.transaction.PaymentTransactionBuilder | ||
import com.algorand.algosdk.crypto.Address | ||
import com.algorand.algosdk.transaction.SignedTransaction | ||
import com.algorand.algosdk.util.Encoder | ||
import com.algorand.algosdk.v2.client.Utils | ||
import com.algorand.algosdk.v2.client.common.AlgodClient | ||
import com.algorand.algosdk.v2.client.model.PendingTransactionResponse | ||
import com.algorand.algosdk.v2.client.model.TransactionParametersResponse | ||
import com.michaeltchuang.cron.data.AlgorandRepository | ||
import com.michaeltchuang.cron.utils.Constants | ||
|
||
import java.time.LocalDate | ||
import java.time.Period | ||
import java.time.format.DateTimeFormatter | ||
import java.util.TimeZone | ||
|
||
private val TAG: String = "AlgorandRepository" | ||
private var client: AlgodClient = AlgodClient( | ||
Constants.ALGOD_API_ADDR, | ||
Constants.ALGOD_PORT, | ||
Constants.ALGOD_API_TOKEN, | ||
Constants.ALGOD_API_TOKEN_KEY | ||
) | ||
|
||
val txHeaders = arrayOf("Content-Type") | ||
val txValues = arrayOf("application/x-binary") | ||
|
||
fun main() { | ||
// Security.removeProvider("BC") | ||
// Security.insertProviderAt(BouncyCastleProvider(), 0) | ||
val repository = AlgorandRepository() | ||
val account = repository.recoverAccount(Constants.TEST_PASSPHRASE) | ||
println() | ||
|
||
if(account == null) { | ||
throw Exception("Could not find account") | ||
} else { | ||
account.address?.apply { repository.sendPayment(account, Constants.COINFLIP_APP_ID_TESTNET, Constants.DEFAULT_MICRO_ALGO_TRANSFER_AMOUNT) } | ||
private var client: AlgodClient = AlgodClient( | ||
Constants.ALGOD_API_ADDR, | ||
Constants.ALGOD_PORT, | ||
Constants.ALGOD_API_TOKEN, | ||
Constants.ALGOD_API_TOKEN_KEY | ||
) | ||
|
||
val txHeaders = arrayOf("Content-Type") | ||
val txValues = arrayOf("application/x-binary") | ||
|
||
fun main() { | ||
val repository = AlgorandRepository() | ||
val account = repository.recoverAccount(Constants.TEST_PASSPHRASE) | ||
|
||
if (account == null) { | ||
throw Exception("Could not find account") | ||
} else { | ||
account.address?.apply { repository.sendPayment(account, Constants.COINFLIP_APP_ID_TESTNET, | ||
Constants.DEFAULT_MICRO_ALGO_TRANSFER_AMOUNT, getGreeting(false)) } | ||
|
||
//send twice if Mondays - 8th vlog | ||
val tz = TimeZone.getTimeZone("America/Los_Angeles") | ||
if(LocalDate.now(tz.toZoneId()).dayOfWeek.value == 1) { | ||
account.address?.apply { repository.sendPayment(account, Constants.COINFLIP_APP_ID_TESTNET, | ||
Constants.DEFAULT_MICRO_ALGO_TRANSFER_AMOUNT, getGreeting(true)) } | ||
} | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
fun getGreeting(isEighth: Boolean) : String { | ||
var vlogNum = calculateVlogNum(isEighth) | ||
|
||
val note = "Volume 2 Vlog ${vlogNum}, have a magical day everyone! - Michael T Chuang" | ||
println(note) | ||
return note | ||
} | ||
|
||
fun calculateVlogNum(isEighth: Boolean) : Int { | ||
val tz = TimeZone.getTimeZone("America/Los_Angeles") | ||
val dateFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd").withZone(tz.toZoneId()) | ||
val from = LocalDate.parse("20230220", dateFormatter) | ||
val to = LocalDate.now(tz.toZoneId()) | ||
val period = Period.between(from, to) | ||
val weeks = period.days / 8 | ||
println("${period.days} days is ${weeks} weeks since Feb 21, 2023") | ||
|
||
if(!isEighth) { | ||
return ((weeks * 8) + (period.days % 7)) | ||
} else { | ||
return (weeks * 8) + 8 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters