using System.Data.SqlClient;
using System.Diagnostics;
static void Main(string[] args)
string rpv, processo, uf, qq;
#region get index & limit
reader = readme("SELECT log, dountil FROM tb_logs WHERE project = 'TRF5 - RPV Updater'");
index = (int)reader["log"];
limit = (int)reader["dountil"];
for (int i = index; i < limit; i++)
Console.WriteLine("Trying: RPV" + i.ToString() + "\n\n");
string htmlOutput = run_cmd(((char)34) + Directory.GetCurrentDirectory().Replace("\\", "/") + "/postRequest.py" + ((char)34), i.ToString() + " R");
htmlOutput = HttpUtility.HtmlDecode(htmlOutput);
using (StringReader sr = new StringReader(htmlOutput))
string line = sr.ReadLine();
if (line.Contains("RPV" + i.ToString()))
line = line.Replace("(", "").Replace("@", "").Replace(")", "");
li = line.IndexOf("Processo Nº");
processo = line.Substring(li + 12, 25);
li = line.IndexOf("RPV" + i.ToString());
string[] splitted = getter(line.Substring(li + 3, line.Length - (li + 3)), "<", "left").Split('-');
Console.WriteLine("Results:\n");
Console.WriteLine("processo: " + processo + " rpv = " + rpv + " uf = " + uf + "\n\n\n");
#region export processo, uf, rpv; onerror: export exception
qq = "INSERT INTO updatative.tb_trf5 (tipo, requisitorio, processo, uf) VALUES ('RPV', '" + rpv + "', '" + processo + "', '" + uf + "')";
execute("UPDATE tb_logs SET query = '" + qq.Replace("'", "''") + "', exception = '" + e.ToString().Replace("'", "''") + "' WHERE project = 'TRF5 - RPV Updater'");
Console.WriteLine("Code Exited at time: " + DateTime.Now.ToString() + "\n\nWith Error:\n" + e.ToString());
System.Environment.Exit(1);
execute("UPDATE tb_logs SET log = " + i.ToString() + " WHERE project = 'TRF5 - RPV Updater'");
execute("UPDATE tb_logs SET log = " + i.ToString() + " WHERE project = 'TRF5 - RPV Updater'");
static string getter(string entry, string delimiter, string type)
while (x != y.Replace(delimiter, ""))
else if (type == "right")
static string run_cmd(string cmd, string args)
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"C:\Python27amd64\python.exe";
start.Arguments = string.Format("{0} {1}", cmd, args);
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using (Process process = Process.Start(start))
using (StreamReader reader = process.StandardOutput)
result = reader.ReadToEnd();
static SqlDataReader readme(string query)
connetionString = "Data Source=177.135.217.58;Initial Catalog=VF;User ID=sa;Password=hllza22";
cnn = new SqlConnection(connetionString);
command = new SqlCommand(query, cnn);
reader = command.ExecuteReader();
static void execute(string query)
connetionString = "Data Source=177.135.217.58;Initial Catalog=VF;User ID=sa;Password=hllza22";
cnn = new SqlConnection(connetionString);
command = new SqlCommand(query, cnn);
command.ExecuteNonQuery();
public static string Left(string param, int length)
string result = param.Substring(0, length);
public static string Right(string param, int length)
string result = param.Substring(param.Length - length, length);
public static string Mid(string param, int startIndex, int length)
string result = param.Substring(startIndex, length);