How can i at least get 3200 latest tweets from a public timeline? this is what i have done currently but it only returns me latest 200 tweets.
void GetUserTimeLine(TwitterContext ctx) {
var statusTweets =
from tweet in twitterCtx.Status
where tweet.Type == StatusType.User &&
tweet.Count == 3200 &&
tweet.ScreenName == "abc"
select tweet;
//PrintTweetsResults(statusTweets);
foreach (var tweet in statusTweets)
{
Console.WriteLine(
"(" + tweet.StatusID + ")" +
"[" + tweet.User.ID + "]" +
tweet.User.Name + ", " +
tweet.Text + ", " +
tweet.CreatedAt);
}
// DEFINE FILE PATH NAME
string dwnloadFilePath = #"C:\temp\Tweet.log";
// CREATE AN EMPTY TEXT FILE
FileStream fs1 = null;
if (!File.Exists(dwnloadFilePath))
{
using (fs1 = File.Create(dwnloadFilePath)) ;
}
// WRITE DATA INTO TEXT FILE
if (File.Exists(dwnloadFilePath))
{
using (StreamWriter sw = new StreamWriter(dwnloadFilePath))
{
statusTweets.ToList().ForEach(
tweet => sw.Write(
"{3}, Tweet ID: {2}, Tweet: {1}\n",
tweet.User.Name, tweet.Text, tweet.StatusID, tweet.CreatedAt));
}
}
Console.ReadLine();
}
Can someone please enlighten me?
Thanks,
10e5x
While you can fetch any of the last 3200 tweets in the time line, you can only fetch them in batches of 200 (see the twitter api for more details.)
You need to requery once you have processed the first 200 entries specifying the max id value as well as the count, where the max id is the lowest id from the set of tweets you have already processed.
Related
I have been looking for some time now and have not been able to find this. How can I set my program up to write or update a file from multiple users but only one group is allowed to open the read what is in the folder?
class Log_File
{
string LogFileDirectory = #"\\server\boiseit$\TechDocs\Headset Tracker\Weekly Charges\Log\Log Files";
string PathToXMLFile = #"\\server\boiseit$\scripts\Mikes Projects\Headset-tracker\config\Config.xml";
string AdditionToLogFile = #"\Who.Did.It_" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Year + ".txt";
XML XMLFile = new XML();
public void ConfigCheck()
{
if (!File.Exists(PathToXMLFile))
{
XMLFile.writeToXML(PathToXMLFile, LogFileDirectory + AdditionToLogFile);
}
}
public void CreateLogFile()
{
if (Directory.GetFiles(LogFileDirectory).Count() == 0)
{
XMLFile.writeToXML(PathToXMLFile, LogFileDirectory + AdditionToLogFile);
CreateFileOrAppend("");
}
else if (!File.Exists(XMLFile.readingXML(PathToXMLFile)))
{
XMLFile.writeToXML(PathToXMLFile, LogFileDirectory + AdditionToLogFile);
CreateFileOrAppend("");
}
else
{
FileInfo dateOfLastLogFile = new FileInfo(XMLFile.readingXML(PathToXMLFile));
DateTime dateOfCreation = dateOfLastLogFile.CreationTime;
if (dateOfLastLogFile.CreationTime <= DateTime.Now.AddMonths(-1))
{
XMLFile.writeToXML(PathToXMLFile, LogFileDirectory + AdditionToLogFile);
CreateFileOrAppend("");
}
}
}
public void CreateFileOrAppend(string whoDidIt)
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetStore((IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly | IsolatedStorageScope.User), null, null))
{
using (StreamWriter myWriter = new StreamWriter(XMLFile.readingXML(PathToXMLFile), true))
{
if (whoDidIt == "")
{
}
else
{
myWriter.WriteLine(whoDidIt);
}
}
}
}
This is my path where it needs to go. I have the special permission to open and write to the folder but my co workers do not. I am not allow to let them have this permission.
If I where to set up a database how would i change this code
LoggedFile.CreateFileOrAppend(Environment.UserName.ToUpper() + "-" + Environment.NewLine + "Replacement Headset To: " + AgentName + Environment.NewLine + "Old Headset Number: " + myDatabase.oldNumber + Environment.NewLine + "New Headset Number: " + HSNumber + Environment.NewLine + "Date: " + DateTime.Now.ToShortDateString() + Environment.NewLine);
I need it to pull current user, the agents name that is being affected the old headset and the new headset, and the time it took place.
While you create file, you have to set access rules to achieve your requirements. .
File.SetAccessControl(string,FileSecurity)
The below link has example
https://msdn.microsoft.com/en-us/library/system.io.file.setaccesscontrol(v=vs.110).aspx
Also the "FileSecurity" class object, which is an input parameter, has functions to set access rules, including group level control.
Below link has example
https://msdn.microsoft.com/en-us/library/system.security.accesscontrol.filesecurity(v=vs.110).aspx
This question will be opened under a new question since I am going to take a different route for recording the data I need Thank you all for the help
Hi thanks for viewing my question! I'm having a little trouble getting multiple data from my database. I'm trying to show multiple data in a single text box and it will not let me, of course.
My code:
string authorised = "notReviewed";
SundownDatabaseEntities5 dbb = new SundownDatabaseEntities5();
System.Windows.Forms.Form ff = System.Windows.Forms.Application.OpenForms["Login"];
int idd = Convert.ToInt32(((Login)ff).idTb.Text);
var getrecordd = dbb.Holidays.Where(a => a.Id == idd).SingleOrDefault();
if (getrecordd.Authorised == authorised)
{
holidaysAuthorisedTb.Text = "Your holiday request (" + getrecordd.Datefrom + " - "+getrecordd.Dateto+") has been sent. Waiting for manager to authorise it...";
}
FirstOrDefault(); gets the first data it finds but I need them all. How would I go about making it so that it will show multiple data instead of one? Thanks guys!
e.g. Text box:
Your holiday request (" + getrecordd.Datefrom + " - "+getrecordd.Dateto+") has been sent. Waiting for manager to authorise it...
Your holiday request (" + getrecordd.Datefrom + " - "+getrecordd.Dateto+") has been authorised.
You can get all records and then use foreach.
var getrecordds = dbb.Holidays.Where(a => a.Id == idd).ToList();
foreach (var getrecordd in getrecordds)
{
if (getrecordd.Authorised == authorised)
{
holidaysAuthorisedTb.Text += "Your holiday request (" + getrecordd.Datefrom + " - "+getrecordd.Dateto+") has been sent. Waiting for manager to authorise it...";
}
else
{
holidaysAuthorisedTb.Text += "Your holiday request (" + getrecordd.Datefrom + " - "+getrecordd.Dateto+") has been sent. Waiting for manager to authorise it..."
}
}
Or use ForEach method
dbb.Holidays.Where(a => a.Id == idd).ForEach ( x =>
{
if (x.Authorised == authorised)
{
holidaysAuthorisedTb.Text += "Your holiday request (" + x.Datefrom + " - "+x.Dateto+") has been sent. Waiting for manager to authorise it...";
}
else
{
holidaysAuthorisedTb.Text += "Your holiday request (" + x.Datefrom + " - "+x.Dateto+") has been sent. Waiting for manager to authorise it..."
}
});
thanks for viewing my question. Basically, when the user clicks on a button, it will either say one of the following in a message box based on what the database has: Your holiday has been authorised, your holiday has been declined or your holiday request has been sent.
I want it so that when the user clicks on the button and there isn't any data in the database because the user hasn't sent a holiday request, to receive a message box saying that they haven't booked an holiday.
Here's my code:
private void button2_Click_1(object sender, EventArgs e)
{
System.Windows.Forms.Form f = System.Windows.Forms.Application.OpenForms["Login"];
SundownDatabaseEntities6 db = new SundownDatabaseEntities6();
int id = Convert.ToInt32(((Login)f).idTb.Text);
var getrecords = db.Holidays.Where(a => a.Id == id).ToList();
foreach (var record in getrecords)
{
if (record.YesOrNo == "yes")
{
MessageBox.Show("The manager has accepted your holiday (From " + record.Datefrom + " - " + record.Dateto + ").");
}
else if (record.YesOrNo == "no")
{
MessageBox.Show("The manager has declined your holiday request (" + record.Datefrom + " - " + record.Dateto + ").");
}
else if (record.YesOrNo == null)
{
MessageBox.Show("Your holiday request (" + record.Datefrom + " - " + record.Dateto + ") has been sent.\nWaiting for manager to authorise it...");
}
else if (record != null)
{
MessageBox.Show("You have not booked an holiday.");
}
}
}
Problem is on the last bit of the code, the 'else if(record != null)' doesn't check if the database is empty. Any suggestions? Thanks!
You should check getrecords.Count()
var getrecords = db.Holidays.Where(a => a.Id == id).ToList();
if (getrecords.Count() == 0)
{
// ... here your logic
}
Or
if (!db.Holidays.Any ())
Because it won't go to foreach if getrecords is empty.
So I've been trying to figure out how to bring an entire line of a .csv file but only the ones who's first string matches another one.
This is what I got so far, all im getting back in my listbox is info from the same random line.
If you guys can help me with the logic it would help out a lot thanks
cbocustinfo.Items.Clear();
lstcustinfo.Items.Clear();
StreamReader infile, transdata;
infile = File.OpenText(#"E:\AS2customers.csv");
transdata= File.OpenText(#"E:\AS2data.csv");
string[] custinfo, names;
string[] custtrans;
do
{
custtrans = transdata.ReadLine().Split(',');
if (custinfo[1] == custtrans[0])
{
lstcustinfo.Items.Add(custtrans[3] + " " + custtrans[4]);
}
}
while (transdata.EndOfStream != True);
infile.Close();
transdata.Close();
Here is where I initialize custinfo
do
{
custinfo = infile.ReadLine().Split(',');
names = custinfo[0].Split(' ');
cbocustinfo.Items.Add(names[0] +" "+ names[1]+ " " + custinfo[1]);
}
while (infile.EndOfStream != true);
If I understand what you're trying to do correctly, maybe it would be easier to just read the files into two strings, then do the splitting and looping over those. I don't know your file formats, so this may be doing unnecessary processing (looping through all the transactions for every customer).
For example:
cbocustinfo.Items.Clear();
lstcustinfo.Items.Clear();
var customers = File.ReadAllText(#"E:\AS2customers.csv")
.Split(new []{Environment.NewLine}, StringSplitOptions.None);
var transactions = File.ReadAllText(#"E:\AS2data.csv")
.Split(new []{Environment.NewLine}, StringSplitOptions.None);
foreach (var customer in customers)
{
var custInfo = customer.Split(',');
var names = custInfo[0].Split(' ');
cbocustinfo.Items.Add(names[0] + " " + names[1]+ " " + custinfo[1]);
foreach (var transaction in transactions)
{
var transInfo = transaction.Split(',');
if (custInfo[1] == transInfo[0])
{
lstcustinfo.Items.Add(transInfo[3] + " " + transInfo[4]);
}
}
}
Why does my ipn script I wrote always fail? It always goes to INVALID even though it matches everything in the query string that paypal sends to me?
notification.cshtml?tx=b78v54b5b55rby92S&st=Completed&amt=3.04&cc=USD&cm=&item_number=&merchant_return_link=Return+to+web+site+name&form_charset=UTF-8
And the part that checks it is:
string LiveURL = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(LiveURL);
// Set request back values.
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
byte[] parameters = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string RequestString = System.Text.Encoding.ASCII.GetString(parameters);
RequestString += "&cmd=_notify-validate";
request.ContentLength = RequestString.Length;
// Send request to PP and get response.
StreamWriter Sout = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
Sout.Write(RequestString);
Sout.Close();
StreamReader Sin = new StreamReader(request.GetResponse().GetResponseStream());
string response = Sin.ReadToEnd();
Sin.Close();
if(result != null && result.OrderStatus == "Confirmed")
{
switch(response)
{
case "VERIFIED":
if(Request["st"] == "Completed")
{
var PPQuery = "SELECT TransactionId, OrderTotal FROM Orders WHERE OrderId = '" + Session["OSFOID"] + "' AND UserId = '" + WebSecurity.CurrentUserId + "'";
var ppQueryResult = database.Query(PPQuery);
foreach(var item in ppQueryResult)
{
decimal fff = 3.04M;
if(item["TransactionId"] != Request["tx"])
{
if(item["OrderTotal"] == TotalPrice)
{
// Payment was a success. Convey that to the user.
output = "Thanks. Order complete.";
}
else
{
// Possible fraud. Log it.
}
}
else
{
// This is a duplicate transaction. Log it and Redirect to homepage.
}
}
}
break;
case "INVALID":
output = "Invalid was returned. Investigate further.";
break;
default:
output = "Other exception has occured. Investigate further and log.";
break;
}
}
The code looks fine. The problem must be with response not matching "VERIFIED".
You're not in Turkey by chance, and changing response to uppercase prior to the comparison? *
*) If the locale is Turkey, uppercasing a string turns i into İ, not I (just one of the many traps with string manipulation)
Within the "VERIFIED" block, check:
if (Request.Params["payment_status"] == "Completed")
{
...
}
Request["st"] is incorrect.
Be sure to set IPN URL in one place in PayPal admin and do not use the other form of return URL checking (can't remember the name of it offhand) and IPN at the same time.
There is no "merchant_return_link" parameter; I think it should be "notify_url"... the URL string and the list of params doesn't look right to me; for example: &cm=&item_number
I know your list of params will be unique for your situation, but here's some sample code where I construct the URL to be passed to PayPal:
protected string GetPayPalURL(string SERVER_URL, string business, string[] itemNames,
int[] quantities, decimal[] amounts, double[] weight, string invoiceID, string transID, string NOTIFY_URL)
{
// Customer will be required to specify delivery address to PayPal - VERY IMPORTANT
const string NO_SHIPPING = "2";
StringBuilder url = new StringBuilder();
url.Append(SERVER_URL + "?cmd=_cart&upload=1");
url.Append("&business=" + HttpUtility.UrlEncode(business));
for (int i = 0; i < itemNames.Length; i++)
{
url.Append("&item_name" + "_" + (i + 1).ToString() + "=" + HttpUtility.UrlEncode(itemNames[i]));
url.Append("&quantity" + "_" + (i + 1).ToString() + "=" + quantities[i].ToString().Replace(",", "."));
url.Append("&amount" + "_" + (i + 1).ToString() + "=" + amounts[i].ToString().Replace(",", "."));
url.Append("&weight" + "_" + (i + 1).ToString() + "=" + weight[i].ToString().Replace(",", "."));
}
url.Append("&no_shipping=" + HttpUtility.UrlEncode(NO_SHIPPING));
url.Append("&custom=" + HttpUtility.UrlEncode(invoiceID));
url.Append("&txn_id=" + HttpUtility.UrlEncode(transID));
url.Append("¬ify_url=" + HttpUtility.UrlEncode(NOTIFY_URL));
return url.ToString();
}
I think the Paypal method you are trying to do is as follows on code project
and if you get payment_status = INVALID, then check the reason in payment_reason
i dont see in the code where you are defining result which is checked in the if, also in the switch you are checking against request, surely this should be against response?