Musich
- fixed database - added music class
This commit is contained in:
48
src/main/java/support/Musich.java
Normal file
48
src/main/java/support/Musich.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package support;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by 20015159 on 11/09/2018.
|
||||
*/
|
||||
public class Musich {
|
||||
|
||||
public static final String SEARCH_URL = "https://www.youtube.com/watch?v=";
|
||||
|
||||
private static final String API_URL = "https://www.googleapis.com/youtube/v3/search?";
|
||||
private static final String KEY = "AIzaSyCtCK0EPR3k_hEEyar0PeY5v9E9UyTX4TM";
|
||||
|
||||
public static List<String> getVideosId(String search) {
|
||||
final int maxResult = 5;
|
||||
try {
|
||||
search = URLEncoder.encode(search, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Map<String, ?> response = Rest.get(API_URL +
|
||||
"maxResults=" + maxResult +
|
||||
"&part=snippet" +
|
||||
"&type=video" +
|
||||
"&q=" + search +
|
||||
"&key=" + KEY);
|
||||
|
||||
List<Map<String, ?>> items = (List<Map<String, ?>>)response.get("items");
|
||||
List<String> videosId = new ArrayList<>(maxResult);
|
||||
|
||||
for(Map<String, ?> obj: items) {
|
||||
Map<String, String> id = (Map<String, String>)obj.get("id");
|
||||
videosId.add(id.get("videoId"));
|
||||
}
|
||||
|
||||
return videosId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public interface Database {
|
||||
}
|
||||
};
|
||||
|
||||
return getThreadStartingEach(runnable, "update-hourly-data", 1);
|
||||
return getThreadStartingEach(runnable, "update-hourly-data", 60);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,17 +54,35 @@ public class LocalDB implements Database {
|
||||
|
||||
@Override
|
||||
public boolean updateHeart(long dateMilliSec, double heartRate) {
|
||||
return query("INSERT INTO heart (day, rate) VALUES ( ' " + new Timestamp(dateMilliSec) + " ', '" + heartRate + "')");
|
||||
Timestamp time = new Timestamp(dateMilliSec);
|
||||
return query("IF NOT EXISTS (" +
|
||||
"SELECT * " +
|
||||
"FROM heart " +
|
||||
"WHERE day = '" + time + "') " +
|
||||
"BEGIN INSERT INTO heart (day, rate) VALUES ( ' " + time + " ', '" + heartRate + "') " +
|
||||
"END;");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateSleep(long dateStartSleep, long duration) {
|
||||
return query("INSERT INTO sleep (sleep_start, duration) VALUES ( ' " + new Timestamp(dateStartSleep) + " ', '" + duration + "')");
|
||||
Timestamp time = new Timestamp(dateStartSleep);
|
||||
return query("IF NOT EXISTS (" +
|
||||
"SELECT * " +
|
||||
"FROM sleep " +
|
||||
"WHERE sleep_start = '" + time + "') " +
|
||||
"BEGIN INSERT INTO sleep (sleep_start, duration) VALUES ( ' " + time + " ', '" + duration + "') " +
|
||||
"END;");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateSteps(long dateMilliSec, long steps) {
|
||||
return query("INSERT INTO steps (day, steps) VALUES ( ' " + new Timestamp(dateMilliSec) + " ', '" + steps + "')");
|
||||
Timestamp time = new Timestamp(dateMilliSec);
|
||||
return query("IF NOT EXISTS (" +
|
||||
"SELECT * " +
|
||||
"FROM steps " +
|
||||
"WHERE day = '" + time + "') " +
|
||||
"INSERT INTO steps (day, steps) VALUES ( ' " + time + " ', '" + steps + "') " +
|
||||
"END;");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,7 +93,7 @@ public class LocalDB implements Database {
|
||||
// calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
// calendar.add(Calendar.DATE, -dayToSubtract);
|
||||
// long time = calendar.getTimeInMillis();
|
||||
long time = System.currentTimeMillis() - (dayToSubtract * 24 * 60 * 1000); // meno 24 giorni per 60 secondi per 100 millisec
|
||||
long time = System.currentTimeMillis() - (dayToSubtract * 24 * 60 * 1000); // meno 24 ore per 60 secondi per 100 millisec
|
||||
|
||||
ResultSet result = conn.createStatement().executeQuery("SELECT * FROM heart WHERE day>='" + new Timestamp(time) + "'");
|
||||
List<HeartRate> list = new LinkedList<>();
|
||||
|
||||
@@ -7,8 +7,12 @@ import java.util.List;
|
||||
// TODO implement
|
||||
public class RemoteDB implements Database {
|
||||
|
||||
public RemoteDB(String url) {
|
||||
public static final String BASE_URL = "https://localhost:"; //TODO inserire il percorso giusto con la porta
|
||||
|
||||
private final String username;
|
||||
|
||||
public RemoteDB(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user