Commit 08044c54 authored by Alan Ing's avatar Alan Ing
Browse files

Refresh

parent a96da32d
No preview for this file type
......@@ -11,16 +11,17 @@ namespace MassGetDb
{
class Program
{
static string connectionString = "AAAAA";
static string connectionString = "AAA";
static string[] keyz = new string[] {
"AAAA",
"BBB"
"AAA",
"BBB"
};
static int keyz_counter = 0;
static string bearer_token = ""; //current token, keysz[keyz_counter]
static int tweets_request_count, followers_request_count;
static void Main(string[] args)
{
create_and_test();
/*
* always listening on the db
* action will take as long as needed,
......@@ -32,22 +33,64 @@ namespace MassGetDb
System.Threading.Thread.Sleep(1000 * 60);
}
}
static void create_and_test()
{
Console.Write(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+" Ping... ");
SqlConnection myConnection = new SqlConnection(connectionString);
try
{
myConnection.Open();
Console.WriteLine("pong!");
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return;
}
SqlCommand create_sql = new SqlCommand(@"IF OBJECT_ID('redJOHN.dbo.RIVER', 'U') IS NOT NULL
DROP TABLE [dbo].[RIVER]
CREATE TABLE [dbo].[RIVER](
[line_id] int IDENTITY(1,1) PRIMARY KEY,
[user] [nchar](50) NULL,
[type] [nchar](20) NULL,
[action] [nchar](10) NULL,
[collection_status] [nchar](20) NULL,
[analysis_status] [nchar](20) NULL,
[ttl] [nchar](10) NULL,
[created_date] [datetime]
) ON [PRIMARY]
", myConnection);
create_sql.ExecuteNonQuery();
SqlCommand test_sql = new SqlCommand("INsert into RIVER([user],type,action,collection_status,analysis_status,ttl,created_date) VALUES('billgates','screennames','tweets','waiting','waiting','-1',GETDATE())", myConnection);
test_sql.ExecuteNonQuery();
try
{
myConnection.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return;
}
}
private static void action()
{
Console.Write("Establishing database connection... ");
Console.Write(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Ping... ");
SqlConnection myConnection = new SqlConnection(connectionString);
SqlConnection myConnection2 = new SqlConnection(connectionString);
try
{
myConnection.Open();
Console.WriteLine("ok got db connection!");
Console.WriteLine("pong!");
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return;
}
SqlCommand myCommand = new SqlCommand("SELECT * FROM redJOHN.dbo.RIVER WHERE status='waiting' and ttl <> 0 ORDER BY created_date", myConnection);
SqlCommand myCommand = new SqlCommand("SELECT * FROM redJOHN.dbo.RIVER WHERE collection_status='waiting' and ttl <> 0 ORDER BY created_date", myConnection);
SqlDataReader dr = myCommand.ExecuteReader();
while (dr.Read())
......@@ -63,13 +106,13 @@ namespace MassGetDb
// grab oldest one marked 'waiting' and change status to in progress
myConnection2.Open();
SqlCommand rewrite = new SqlCommand("UPDATE redJOHN.dbo.RIVER SET status = 'in progress' where line_id = " + line_id, myConnection2);
SqlCommand rewrite = new SqlCommand("UPDATE redJOHN.dbo.RIVER SET collection_status = 'in progress' where line_id = " + line_id, myConnection2);
rewrite.ExecuteNonQuery();
// then take those values and decide what to do with them.
process_input_line(user, type, action, ttl);
SqlCommand rewrite2 = new SqlCommand("UPDATE redJOHN.dbo.RIVER SET status = 'completed' where line_id = " + line_id, myConnection2);
SqlCommand rewrite2 = new SqlCommand("UPDATE redJOHN.dbo.RIVER SET collection_status = 'completed' where line_id = " + line_id, myConnection2);
rewrite2.ExecuteNonQuery();
myConnection2.Close();
}
......@@ -113,6 +156,7 @@ namespace MassGetDb
else { return; }
string response = process_request(method, host, endpoint, query, body, action); // pass in action to ensure correct requests remaining
dynamic stuff = null;
if (action.Equals("tweets")) { response = @"{ info: " + response + "}"; } // tweets json structured weirdly (starts with arrays)
......@@ -136,8 +180,8 @@ namespace MassGetDb
for (int i = 0; i < stuff.ids.Count; i++)
{
SqlCommand sc = sc1.CreateCommand();
string sql = @"INSERT INTO [redJOHN].[dbo].[RIVER]( [created_date] ,[user] ,[type] ,[action] ,[status] ,[ttl])
VALUES( GETDATE() ,'" + (stuff.ids[i]).ToString().Trim() + "' ,'ids' ,'tweets' ,'waiting' ,-1)";
string sql = @"INSERT INTO [redJOHN].[dbo].[RIVER]( [created_date] ,[user] ,[type] ,[collection_status], [analysis_status] ,[status] ,[ttl])
VALUES( GETDATE() ,'" + (stuff.ids[i]).ToString().Trim() + "' ,'ids' ,'tweets' ,'waiting','waiting' ,-1)";
sc.CommandText = sql;
sc.ExecuteNonQuery();
sql = @"INSERT INTO [redJOHN].[dbo].[RIVER]( [created_date] ,[user] ,[type] ,[action] ,[status] ,[ttl])
......@@ -207,6 +251,19 @@ namespace MassGetDb
p11.Value = ("" + stuff.info[i].in_reply_to_user_id_str).Trim();
myCommand.Parameters.Add(p11);
{
string name1 = "" + stuff.info[i].in_reply_to_screen_name;
name1 = name1.Trim();
string name2 = "" + stuff.info[i].in_reply_to_user_id_str;
name2 = name2.Trim();
SqlCommand map_sql = new SqlCommand(@"IF NOT EXISTS (SELECT 1 FROM [redJOHN].[dbo].[BUCKINGHAM_PALACE]
WHERE screen_name = '" + name1 + @"')
INSERT INTO [redJOHN].[dbo].[BUCKINGHAM_PALACE](screen_name,user_id_str)
values ('" + name1 + @"','" + name2 + @"') ", sc1);
map_sql.ExecuteNonQuery();
}
SqlParameter p12 = new SqlParameter("@lang", SqlDbType.NChar);
p12.Value = ("" + stuff.info[i].lang).Trim();
myCommand.Parameters.Add(p12);
......@@ -238,6 +295,19 @@ namespace MassGetDb
SqlParameter p19 = new SqlParameter("@user_id_str", SqlDbType.NChar);
p19.Value = ("" + stuff.info[i].user.id_str).Trim();
myCommand.Parameters.Add(p19);
if (type.Equals("screennames"))
{
SqlCommand map_sql = new SqlCommand(@"IF NOT EXISTS (SELECT 1 FROM [redJOHN].[dbo].[BUCKINGHAM_PALACE]
WHERE screen_name = '"+line_user+@"')
INSERT INTO [redJOHN].[dbo].[BUCKINGHAM_PALACE](screen_name,user_id_str)
values ('"+line_user+@"','"+(""+stuff.info[i].user.id_str).Trim()+@"') ", sc1);
map_sql.ExecuteNonQuery();
}
//user = "screen_name=" + line_user;
myCommand.CommandTimeout = 36000;
myCommand.ExecuteNonQuery();
......
c:\users\alaning\documents\visual studio 2013\Projects\MassGetDb\MassGetDb\bin\Debug\MassGetDb.exe.config
C:\Users\Administrator\Documents\Visual Studio 2013\Projects\massgetdb\MassGetDb\bin\Debug\MassGetDb.exe.config
C:\Users\Administrator\Documents\Visual Studio 2013\Projects\massgetdb\MassGetDb\bin\Debug\MassGetDb.exe
C:\Users\Administrator\Documents\Visual Studio 2013\Projects\massgetdb\MassGetDb\bin\Debug\MassGetDb.pdb
C:\Users\Administrator\Documents\Visual Studio 2013\Projects\massgetdb\MassGetDb\bin\Debug\Newtonsoft.Json.dll
C:\Users\Administrator\Documents\Visual Studio 2013\Projects\massgetdb\MassGetDb\bin\Debug\Newtonsoft.Json.xml
C:\Users\Administrator\Documents\Visual Studio 2013\Projects\massgetdb\MassGetDb\obj\Debug\MassGetDb.csprojResolveAssemblyReference.cache
C:\Users\Administrator\Documents\Visual Studio 2013\Projects\massgetdb\MassGetDb\obj\Debug\MassGetDb.exe
C:\Users\Administrator\Documents\Visual Studio 2013\Projects\massgetdb\MassGetDb\obj\Debug\MassGetDb.pdb
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment