166 lines
5.2 KiB
Java
166 lines
5.2 KiB
Java
import java.awt.*;
|
|
import java.io.*;
|
|
import java.util.ArrayList;
|
|
import java.util.Map;
|
|
import java.util.Random;
|
|
import java.util.TreeMap;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
public class Main {
|
|
|
|
ArrayList<File> dirs = new ArrayList<>();
|
|
static TreeMap<String, ArrayList<File>> cal = new TreeMap<>();
|
|
public static void main(String[] args) throws InterruptedException {
|
|
//\\schatzkammer\homes\bene\Photos\MobileBackup\A52s von Benedikt\DCIM\Camera
|
|
//P:\Android Xcover2
|
|
|
|
//findDirsFrom2009();
|
|
readFile("cal_2009-2023.txt");
|
|
readFile("cal_androidXcover2.txt");
|
|
readFile("cal_A52s.txt");
|
|
//createFile();
|
|
//traverse(new File("\\\\schatzkammer\\homes\\bene\\Photos\\MobileBackup\\A52s von Benedikt\\DCIM\\Camera"), true, "([0-9]{4})([0-9]{2})([0-9]{2})");
|
|
//createFile();
|
|
while(true) {
|
|
showRandomImageOfDay("07-03");
|
|
Thread.sleep(2000);
|
|
}
|
|
}
|
|
|
|
static void showRandomImageOfDay(String date)
|
|
{
|
|
ArrayList<File> temp = cal.get(date);
|
|
showImage(getRandomFile(temp));
|
|
}
|
|
|
|
static File getRandomFile(ArrayList<File> list)
|
|
{
|
|
Random rand = new Random();
|
|
int randomIndex = rand.nextInt(list.size());
|
|
File f = list.get(randomIndex);
|
|
if(f.isDirectory())
|
|
{
|
|
File[] children = f.listFiles();
|
|
if(children.length == 0)
|
|
return getRandomFile(list);
|
|
randomIndex = rand.nextInt(children.length);
|
|
return children[randomIndex];
|
|
}
|
|
return f;
|
|
}
|
|
|
|
static void showImage(File file)
|
|
{
|
|
System.out.println(file.getAbsolutePath());
|
|
if (Desktop.isDesktopSupported()) {
|
|
try {
|
|
Desktop desktop = Desktop.getDesktop();
|
|
desktop.open(file);
|
|
} catch (IOException ex) {}
|
|
}
|
|
}
|
|
|
|
static void readFile(String filename)
|
|
{
|
|
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
|
|
String line;
|
|
while ((line = reader.readLine()) != null) {
|
|
String[] lineS = line.split("_:_");
|
|
String key = lineS[0];
|
|
if(!cal.containsKey(key))
|
|
cal.put(key, new ArrayList<>());
|
|
lineS = lineS[1].split(",");
|
|
for(String s: lineS)
|
|
{
|
|
File f = new File(s);
|
|
if(!f.exists())
|
|
{
|
|
System.out.print("ERROR "+f+" existiert nicht!");
|
|
|
|
}
|
|
else{
|
|
cal.get(key).add(f);
|
|
}
|
|
}
|
|
}
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
static void findDirsFrom2009()
|
|
{
|
|
for (int i = 2009; i < 2100; i++) {
|
|
File temp = new File(i+"");
|
|
if(temp.exists())
|
|
traverse(temp, false, "([0-9]{4})[-_]([0-9]{2})[-_]([0-9]{2})");
|
|
}
|
|
}
|
|
|
|
static void createFile()
|
|
{
|
|
Map.Entry<String, ArrayList<File>> entry = cal.pollFirstEntry();
|
|
try {
|
|
FileWriter fw = new FileWriter("output.txt");
|
|
while(entry != null)
|
|
{
|
|
fw.append(entry.getKey()).append("_:_");
|
|
for(File file: entry.getValue())
|
|
{
|
|
fw.append(file.getAbsolutePath()).append(",");
|
|
}
|
|
fw.append("\n");
|
|
entry = cal.pollFirstEntry();
|
|
|
|
}
|
|
|
|
System.out.println("Der FileWriter hat die Datei erfolgreich beschrieben!");
|
|
fw.close();
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
public static void traverse(File directory, Boolean findFiles, String pattern)
|
|
{
|
|
File[] files = directory.listFiles();
|
|
for (File file : files) {
|
|
if(file.isDirectory() )
|
|
{
|
|
//File is a file
|
|
Pattern pPattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
|
|
String filename = file.getName();
|
|
Matcher matcher = pPattern.matcher(filename);
|
|
if(matcher.find()){
|
|
String key = matcher.group(2)+"-"+matcher.group(3);
|
|
if(!cal.containsKey(key))
|
|
{
|
|
cal.put(key, new ArrayList<>());
|
|
}
|
|
cal.get(key).add(file);
|
|
}
|
|
traverse(file, findFiles, pattern);
|
|
|
|
}
|
|
else if(findFiles)
|
|
{
|
|
//File ist ein Directory
|
|
Pattern pPattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
|
|
String filename = file.getName();
|
|
Matcher matcher = pPattern.matcher(filename);
|
|
if(matcher.find()){
|
|
String key = matcher.group(2)+"-"+matcher.group(3);
|
|
if(!cal.containsKey(key))
|
|
{
|
|
cal.put(key, new ArrayList<>());
|
|
}
|
|
cal.get(key).add(file);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|