Merge pull request 'pi-ux-ce-patch-1' (#1) from pi-ux-ce-patch-1 into main
Gitea Actions Demo / Explore-Gitea-Actions (8.0.x) (push) Failing after 1m3s
Gitea Actions Demo / Explore-Gitea-Actions (8.0.x) (push) Failing after 1m3s
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
+70
-65
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Data.SQLite;
|
||||
using System.Runtime.InteropServices;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
@@ -15,7 +17,26 @@ class Program
|
||||
public static readonly string filePath = Path.Combine(folder_path, "episodes-watched.csv");
|
||||
public static readonly string overrideBrowser = Path.Combine(folder_path, "overrideBrowser.xml");
|
||||
|
||||
private static void openit(string url)
|
||||
static SQLiteConnection CreateConnection()
|
||||
{
|
||||
|
||||
SQLiteConnection sqliteconn;
|
||||
// Create a new database connection:
|
||||
var sqllitedatasource = $"Data Source={folder_path}/database.db;Version=3;New=True;Compress=True;";
|
||||
sqliteconn = new SQLiteConnection(sqllitedatasource);
|
||||
// Open the connection:
|
||||
try
|
||||
{
|
||||
sqliteconn.Open();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
return sqliteconn;
|
||||
}
|
||||
|
||||
private static void Openit(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -84,92 +105,77 @@ class Program
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static void saveIntoFile(string data_input)
|
||||
static object RunSQLQuery(SQLiteConnection conn, string query)
|
||||
{
|
||||
|
||||
//first check if folder and file exist
|
||||
|
||||
if (!Directory.Exists(folder_path))
|
||||
Directory.CreateDirectory(folder_path);
|
||||
|
||||
using (StreamWriter w = new StreamWriter(filePath, true))
|
||||
SQLiteDataReader sqlite_datareader;
|
||||
SQLiteCommand sqlite_cmd;
|
||||
sqlite_cmd = conn.CreateCommand();
|
||||
sqlite_cmd.CommandText = query;
|
||||
sqlite_datareader = sqlite_cmd.ExecuteReader();
|
||||
if (sqlite_datareader.Read())
|
||||
{
|
||||
w.WriteLine(data_input);
|
||||
|
||||
return sqlite_datareader["result"];
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static void SaveIntoDatabase(SQLiteConnection conn,int season, int episode)
|
||||
{
|
||||
SQLiteCommand sqliteCmd;
|
||||
sqliteCmd = conn.CreateCommand();
|
||||
string updateQuery = $"update episodes set seen=1 WHERE season = {season} and episode = {episode}";
|
||||
sqliteCmd.CommandText = updateQuery;
|
||||
sqliteCmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
||||
string url_generated;
|
||||
string urlGenerated;
|
||||
int randomSeason;
|
||||
int randomEpisode;
|
||||
|
||||
SQLiteConnection sqliteconn;
|
||||
sqliteconn = CreateConnection();
|
||||
bool restart = false;
|
||||
do
|
||||
{
|
||||
restart = false;
|
||||
|
||||
//get maximum number of seasons
|
||||
string maximumNumberOfSeasonsQuery = "SELECT COUNT(DISTINCT season) as result FROM episodes;";
|
||||
int maximumNumberSeasons = Convert.ToInt32(RunSQLQuery(sqliteconn, maximumNumberOfSeasonsQuery));
|
||||
|
||||
int maximum_number_seasons = 35;
|
||||
string root_url = "https://kisscartoon.top/episode/the-simpsons-season-";
|
||||
|
||||
//random for the season
|
||||
Random rnd = new Random();
|
||||
int random_season = rnd.Next(1, maximum_number_seasons);
|
||||
randomSeason = rnd.Next(1, maximumNumberSeasons);
|
||||
|
||||
Console.WriteLine("random season:"+random_season);
|
||||
Console.WriteLine("random season: "+randomSeason);
|
||||
|
||||
//get maximum number of episodes for this season
|
||||
string maximumNumberOfEpisodesQuery = $"SELECT COUNT() as result FROM episodes WHERE season = {randomSeason};";
|
||||
int maximumNumberOfEpisodes = Convert.ToInt32(RunSQLQuery(sqliteconn, maximumNumberOfEpisodesQuery));
|
||||
|
||||
//dictionary for the maximum number of episodes
|
||||
Dictionary<int, int> Season_nbr_Episodes = new Dictionary<int, int>();
|
||||
Season_nbr_Episodes.Add(1,13);
|
||||
Season_nbr_Episodes.Add(2,22);
|
||||
Season_nbr_Episodes.Add(3,24);
|
||||
Season_nbr_Episodes.Add(4,22);
|
||||
Season_nbr_Episodes.Add(5,22);
|
||||
Season_nbr_Episodes.Add(6,25);
|
||||
Season_nbr_Episodes.Add(7,25);
|
||||
Season_nbr_Episodes.Add(8,25);
|
||||
Season_nbr_Episodes.Add(9,25);
|
||||
Season_nbr_Episodes.Add(10,23);
|
||||
Season_nbr_Episodes.Add(11,22);
|
||||
Season_nbr_Episodes.Add(12,21);
|
||||
Season_nbr_Episodes.Add(13,22);
|
||||
Season_nbr_Episodes.Add(14,22);
|
||||
Season_nbr_Episodes.Add(15,22);
|
||||
Season_nbr_Episodes.Add(16,21);
|
||||
Season_nbr_Episodes.Add(17,22);
|
||||
Season_nbr_Episodes.Add(18,22);
|
||||
Season_nbr_Episodes.Add(19,20);
|
||||
Season_nbr_Episodes.Add(20,21);
|
||||
Season_nbr_Episodes.Add(21,23);
|
||||
Season_nbr_Episodes.Add(22,22);
|
||||
Season_nbr_Episodes.Add(23,22);
|
||||
Season_nbr_Episodes.Add(24,22);
|
||||
Season_nbr_Episodes.Add(25,22);
|
||||
Season_nbr_Episodes.Add(26,22);
|
||||
Season_nbr_Episodes.Add(27,22);
|
||||
Season_nbr_Episodes.Add(28,22);
|
||||
Season_nbr_Episodes.Add(29,21);
|
||||
Season_nbr_Episodes.Add(30,23);
|
||||
Season_nbr_Episodes.Add(31,22);
|
||||
Season_nbr_Episodes.Add(32,22);
|
||||
Season_nbr_Episodes.Add(33,22);
|
||||
Season_nbr_Episodes.Add(34,22);
|
||||
Season_nbr_Episodes.Add(35,18);
|
||||
|
||||
int random_episode = rnd.Next(1,Season_nbr_Episodes[random_season]);
|
||||
|
||||
Console.WriteLine("random episode:"+random_episode);
|
||||
randomEpisode = rnd.Next(1, maximumNumberOfEpisodes);
|
||||
Console.WriteLine("random episode: "+randomEpisode);
|
||||
|
||||
//url generated
|
||||
url_generated = root_url + random_season + "-episode-"+random_episode;
|
||||
string urlGeneratedQuery = $"SELECT url as result FROM episodes WHERE season = {randomSeason} and episode = {randomEpisode};";
|
||||
urlGenerated = Convert.ToString(RunSQLQuery(sqliteconn, urlGeneratedQuery));
|
||||
|
||||
Console.WriteLine(url_generated);
|
||||
|
||||
if (CheckEpisodeAlreadyRun(url_generated))
|
||||
//CheckEpisodeAlreadyRun
|
||||
string checkEpisodeAlreadyRunQuery = $"SELECT seen as result FROM episodes WHERE season = {randomSeason} and episode = {randomEpisode};";
|
||||
bool checkEpisodeAlreadyRun = Convert.ToBoolean(RunSQLQuery(sqliteconn, checkEpisodeAlreadyRunQuery));
|
||||
|
||||
if (checkEpisodeAlreadyRun)
|
||||
{
|
||||
//return;
|
||||
restart = true;
|
||||
@@ -180,11 +186,10 @@ class Program
|
||||
|
||||
|
||||
} while (restart);
|
||||
openit(url_generated);
|
||||
|
||||
saveIntoFile(url_generated);
|
||||
|
||||
Console.WriteLine("urlGenerated "+urlGenerated);
|
||||
Openit(urlGenerated);
|
||||
|
||||
SaveIntoDatabase(sqliteconn,randomSeason,randomEpisode);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Binary file not shown.
Reference in New Issue
Block a user