Created
July 19, 2020 04:46
-
-
Save Wieku/0db062a13a3738fea4397e1ecaaa6cbe to your computer and use it in GitHub Desktop.
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
import java.awt.Dimension | |
import java.io.File | |
import java.io.FileOutputStream | |
import java.lang.Exception | |
import java.net.URL | |
import java.text.SimpleDateFormat | |
import java.util.* | |
import javax.net.ssl.HttpsURLConnection | |
import javax.swing.BoxLayout | |
import javax.swing.JFrame | |
import javax.swing.JLabel | |
import javax.swing.JPanel | |
private const val baseMsSleep = 600000 | |
private val format = SimpleDateFormat("yyyy-MM-dd HH-mm") | |
private val format2 = SimpleDateFormat("HH:mm:ss") | |
fun main() { | |
var lastTime = 0L | |
val frame = JFrame() | |
val toolLabel = JLabel("PAO backup tool.") | |
val nextLabel = JLabel("Next backup at: 00:00:00") | |
val panel = JPanel() | |
panel.layout = BoxLayout(panel, BoxLayout.PAGE_AXIS) | |
panel.add(toolLabel) | |
panel.add(nextLabel) | |
frame.add(panel) | |
frame.title = "PAOBackup" | |
frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE | |
frame.pack() | |
frame.size = Dimension ((frame.width * 1.5).toInt(), frame.height) | |
frame.setLocationRelativeTo(null) | |
frame.isVisible = true | |
while (true) { | |
val time = System.currentTimeMillis() | |
val overhead = if(lastTime == 0L) 0 else baseMsSleep - (time - lastTime) | |
lastTime = time | |
try { | |
File("pao").mkdirs() | |
val outFile = File("pao/${format.format(Date())}.png") | |
val url = URL("https://pixelanarchy.online/canvas.png") | |
val sslConnection = url.openConnection() as HttpsURLConnection | |
sslConnection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:221.0) Gecko/20100101 Firefox/31.0"); | |
sslConnection.inputStream.use { it -> | |
FileOutputStream(outFile).use { it2 -> | |
it.copyTo(it2) | |
println("${outFile.name} saved!") | |
} | |
} | |
sslConnection.disconnect() | |
} catch (e: Exception) { | |
e.printStackTrace() | |
} | |
println("Waiting 10 minutes...") | |
nextLabel.text = "Next backup at: " + format2.format(Date(Date().time + baseMsSleep + overhead)) | |
Thread.sleep(baseMsSleep + overhead) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment