C# - Geocode pharmacy by name and location - c#

How can I find the coordinates of a pharmacy by it name and location?
I'm trying to search with the Google geocode API like this:
var pharmacyName = "Farmácia Ereirense";
var address = "Cartaxo, Santarém";
var url = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + pharmacyName + ", " + address + "&sensor=false";
but I only got ZERO_RESULTS on the GeoResponse Status, and if I google "Farmácia Ereirense, Cartaxo, Santarém" it found the right location...
I already tried to do:
var pharmacyName = "Farmácia Ereirense";
var address = "Cartaxo, Santarém";
var url = "https://maps.googleapis.com/maps/api/place/nearbysearch/xml?name=" + pharmacyName + ", " + address + "&key=" + apiKey;
but I got the INVALID_REQUEST result.
Documentation I based on

Finally I found the solution! We can do a Text Search request like this:
var pharmacyName = "Farmácia Ereirense";
var address = "Cartaxo, Santarém";
var url = "https://maps.googleapis.com/maps/api/place/textsearch/xml?query=" + pharmacyName + ", " + address + "&key=" + apiKey;
And it works just fine, like Google's search.
Documentation

Related

How to solve the error in the below email content in C#

I am using C# MVC Architecture.
I am going to retrieve the questions from the database and display in the email content as a list of questions.
Below is the method of the email template.
public bool SendJobAcceptanceToRecruiter(string recruiterName, string recruiterEmail, string jobTitle,string joblink, string mailBody, string organization, List<JobQuestion> ques)
{
string subject = "Job Advert Accepted - " + jobTitle + "-" + organization;
var generaltemplate = GetEmailTemplate("GENERAL EMAIL TEMPLATE");
var template = "<br/>Hello " + organization + "<br/>" +
"<br/>Your Job Advert has now been accepted.<br/>" +
"<br/>View Job Posted: " + joblink + "<br/>" +
"<br/>Questions Posted: " + ques + "<br/>" +
"<br/>Please contact us if you need more information.<br/>";
var body = generaltemplate.Replace("#Content", template);
body = body.Replace("#Orgname", organization);
body = body.Replace("#JobLink", joblink) + GetEmailFooter();
var result = _emailProvider.SendEmail(recruiterEmail, subject, body, true);
return result;
}
Here for the List of questions, I get the questions as below.
I want to display the 'Question' in the second image as list of questions(In the above case as the count is 7,want to display the 7 questions) with numbering starting from 1.(Number of questions may differ according to the advert.) as a list in the email content.
Every other details(jobTitle,JobLink,RecruiterEmail etc..) are displayed in the email.
Only the 'ques' under Questions Posted: in the email content are displayed as
[![enter image description here][3]][3]
I want the content to be displayed as,
1.Question 1
2.Question 3
3.Question 3
...
How can I solve this?
You need to "unfold" the list of questions, if you do that, you'll have all the freedom you need.
In stead of:
"<br/>Questions Posted: " + ques + "<br/>"
use something like this:
"<br/>Questions Posted: " + string.Join(", ",Enumerable.Range(0, ques.Count()).Select(n => n.Description).ToArray()) + "<br/>"
Or for better readability:
var template = "<br/>Hello " + organization + "<br/>" +
"<br/>Your Job Advert has now been accepted.<br/>" +
"<br/>View Job Posted: " + joblink + "<br/>" +
"<br/>Questions Posted: ";
foreach(var question in ques)
template += $"somthing {question.Description} something"
template += "<br/>Please contact us if you need more information.<br/>";
var body = generaltemplate.Replace("#Content", template);
Further optimization: use a StringBuilder:
var sb = new StringBuilder();
sb.AppendLine("<br/>Hello " + organization + "<br/>");
sb.AppendLine("<br/>Your Job Advert has now been accepted.<br/>");
sb.AppendLine("<br/>View Job Posted: " + joblink + "<br/>");
sb.AppendLine("<br/>Questions Posted: ");
foreach(var question in ques)
{
sb.AppendLine($"somthing {question.Description} something");
}
sb.AppendLine("<br/>Please contact us if you need more information.<br/>");
var body = generaltemplate.Replace("#Content", sb.ToString());
Addition: for numbering you have various options. Here's a simple one to understand:
var sb = new StringBuilder();
sb.AppendLine("<br/>Hello " + organization + "<br/>");
sb.AppendLine("<br/>Your Job Advert has now been accepted.<br/>");
sb.AppendLine("<br/>View Job Posted: " + joblink + "<br/>");
sb.AppendLine("<br/>Questions Posted: ");
int number = 0;
foreach(var question in ques)
{
sb.AppendLine($"QUESTION {++number}");
sb.AppendLine($"somthing {question.Description} something");
}
sb.AppendLine("<br/>Please contact us if you need more information.<br/>");
var body = generaltemplate.Replace("#Content", sb.ToString());

Im looking for a way to delete the bot command after the bot has posted in Discord code written in Discord.net

Below is The code after the embed message is posted I would like the bot to delete the command that it was give to post the embed. Also if anyone knows how to add a footer to this embed that would be awesome
if (raid == "gos")
{
if (day == "Sun")
{
var filename = "gos_Sun.png";
var embed = new EmbedBuilder()
{
Title = "Garden of Salvation",
Description = "```" + day + ", " + date + " # " + time + " " + ampm + " " + "\n" + description + "```" + description2,
ImageUrl = $"attachment://{filename}",
}.Build();
SentEmbed = await Context.Channel.SendFileAsync(filename, embed: embed);
await SentEmbed.AddReactionsAsync(myReactions);
}
}
var footer = new EmbedFooterBuilder().WithText("React Below");
if (raid == "gos")
{
if (day == "Sun")
{
var filename = "gos_Sun.png";
var embed = new EmbedBuilder()
{
Title = "Garden of Salvation",
Description = "```" + day + ", " + date + " # " + time + " " + ampm + " " + "\n" + description + "```" + description2,
ImageUrl = $"attachment://{filename}",
}.WithFooter(footer).Build();

Yahoo Weather API by Lat and Lon

I'm writing a weather app in Xamarin.Form. I am using the Yahoo API. I have no problem getting the weather by the city name parameter. However, when I change the code to use longitude and latitude, the weather does not appear.
To download the weather I use the example from the page: https://developer.yahoo.com/weather/documentation.html#oauth-csharp
I processed it in the following way:
lSign = string.Format(
"format={0}&" +
"lat={1}&" +
"lon={2}&" +
"oauth_consumer_key={3}&" +
"oauth_nonce={4}&" +
"oauth_signature_method={5}&" +
"oauth_timestamp={6}&" +
"oauth_version={7}&" +
"u={8}",
cFormat,
szerokosc,
dlugosc,
cConsumerKey,
lNonce,
cOAuthSignMethod,
lTimes,
cOAuthVersion,
jednostka.ToString().ToLower()
(...)
url = cURL + "?lat=" + szerokosc + "&lon=" + dlugosc + "&u=" + jednostka.ToString().ToLower() + "&format=" + cFormat;
According to the documentation, lSign is used for authentication. It should not be changed, remove these "lat={1}&" + "lon={2}&" from that strings.
It says Please don't simply change value of any parameter without
re-sorting.
The location information should be involved in the request url and the authorization information is added in the header.
// Add Authorization
lClt.Headers.Add ( "Authorization", _get_auth () );
// The request URL
lURL = cURL + "?" + "lat=" + szerokosc + "&lon=" + dlugosc + "&format=" + cFormat;
Unfortunately, the simple removal of " lat = {1} & " + " lon = {2} & " from variable lSign does not solve the problem.
For example, to get weather data by the city name I use:
lSign = string.Format(
"format={0}&" +
"location={1}&" +
"oauth_consumer_key={2}&" +
"oauth_nonce={3}&" +
"oauth_signature_method={4}&" +
"oauth_timestamp={5}&" +
"oauth_version={6}&" +
"u={7}",
cFormat,
miasto,
cConsumerKey,
lNonce,
cOAuthSignMethod,
lTimes,
cOAuthVersion,
jednostka.ToString().ToLower()
and
url = cURL + "?location=" + Uri.EscapeDataString(miasto) + "&u=" + jednostka.ToString().ToLower() + "&format=" + cFormat;
and
string headerString = _get_auth();
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/" + cFormat;
webClient.Headers[HttpRequestHeader.Authorization] = headerString;
webClient.Headers.Add("X-Yahoo-App-Id", cAppID);
byte[] reponse = webClient.DownloadData(url);
string lOut = Encoding.ASCII.GetString(reponse);

restsharp how to add key value pair as parameter

I am trying to consume stripe.com api with restsharp, using the charge command
https://stripe.com/docs/api/php#create_charge
there's an opportunity to pass metadata as key value pairs but I don't seem to succeed
const string baseUrl = "https://api.stripe.com/";
const string endPoint = "v1/charges";
var apiKey = this.SecretKey;
var client = new RestClient(baseUrl) { Authenticator = new HttpBasicAuthenticator(apiKey, "") };
var request = new RestRequest(endPoint, Method.POST);
request.AddParameter("card", token);
request.AddParameter("amount", wc.totalToPayForStripe);
request.AddParameter("currency", "eur");
request.AddParameter("description", wc.crt.cartid + " - " + wc.co.oid);
request.AddParameter("metadata", "{cartid: " + wc.crt.cartid + ", oid: " + wc.co.oid + "}");
request.AddParameter("statement_description", "# " + wc.crt.cartid);
request.AddParameter("description", wc.crt.cartid + " - " + wc.co.oid);
Always getting the following error:
Invalid metadata: metadata must be a set of key-value pairs
Clearly I don't pass the key value pair the way I should but I can't find any restsharp documentation on that.
Anyone can help?
Try this:
const string baseUrl = "https://api.stripe.com/";
const string endPoint = "v1/charges";
var apiKey = this.SecretKey;
var client = new RestClient(baseUrl) { Authenticator = new HttpBasicAuthenticator(apiKey, "") };
var request = new RestRequest(endPoint, Method.POST);
request.AddParameter("card", token);
request.AddParameter("amount", wc.totalToPayForStripe);
request.AddParameter("currency", "eur");
request.AddParameter("description", wc.crt.cartid + " - " + wc.co.oid);
request.AddParameter("metadata[cartid]", wc.crt.cartid);
request.AddParameter("metadata[oid]", wc.co.oid);
request.AddParameter("statement_description", "# " + wc.crt.cartid);
request.AddParameter("description", wc.crt.cartid + " - " + wc.co.oid);
For some reason HTTP Post requests can not accept key-value objects and must be sent in this type of format. This isn't a stripe restriction, but HTTP in general.
I think it's telling you to enter them as such:
request.AddParameter("metadata", "[ { cartid: " + wc.crt.cartid + "} ,{ oid: " + wc.co.oid + " }]" );

Code for Google Analytic product hit in c#

I'm new in google analytic. I go through some regarding this. I found that there is no direct method to hit a windows application in google analytic. But i found some solutions in stackoverflow. I tried that, but didn't work for me. Below is the code that I'm using.
private void analyticsmethod4(string trackingId, string pagename)
{
Random rnd = new Random();
long timestampFirstRun, timestampLastRun, timestampCurrentRun, numberOfRuns;
// Get the first run time
timestampFirstRun = DateTime.Now.Ticks;
timestampLastRun = DateTime.Now.Ticks - 5;
timestampCurrentRun = 45;
numberOfRuns = 2;
// Some values we need
string domainHash = "123456789"; // This can be calcualted for your domain online
int uniqueVisitorId = rnd.Next(100000000, 999999999); // Random
string source = "Shop";
string medium = "medium123";
string sessionNumber = "1";
string campaignNumber = "1";
string culture = Thread.CurrentThread.CurrentCulture.Name;
string screenRes = Screen.PrimaryScreen.Bounds.Width + "x" + Screen.PrimaryScreen.Bounds.Height;
string statsRequest = "http://www.google-analytics.com/__utm.gif" +
"?utmwv=4.6.5" +
"&utmn=" + rnd.Next(100000000, 999999999) +
// "&utmhn=hostname.mydomain.com" +
"&utmcs=-" +
"&utmsr=" + screenRes +
"&utmsc=-" +
"&utmul=" + culture +
"&utmje=-" +
"&utmfl=-" +
"&utmdt=" + pagename + // Here i passed my profile name "MyWindowsApp"
"&utmhid=1943799692" +
"&utmr=0" +
"&utmp=" + pagename +
"&utmac=" + trackingId + //Tracking id : ie "UA-XXXXXXXX-X"
"&utmcc=" +
"__utma%3D" + domainHash + "." + uniqueVisitorId + "." + timestampFirstRun + "." + timestampLastRun + "." + timestampCurrentRun + "." + numberOfRuns +
"%3B%2B__utmz%3D" + domainHash + "." + timestampCurrentRun + "." + sessionNumber + "." + campaignNumber + ".utmcsr%3D" + source + "%7Cutmccn%3D(" + medium + ")%7Cutmcmd%3D" + medium + "%7Cutmcct%3D%2Fd31AaOM%3B";
try
{
using (var client = new WebClient())
{
//byte[] bt = client.DownloadData(statsRequest);
Stream data = client.OpenRead(statsRequest);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
MessageBox.Show(s);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
This example is also got from this site itself. I don't know where was the problem. Please direct me, how can i make it. This is the output i'm getting "GIF89a".
Thanks
Bobbin Paulose
So it's working. The Google Analytics call loads a tiny GIF image, and the querystring parameters provided in the request trigger all the Google Analytics goodness. If you're getting a response back, you have registered your event successfully with Google.

Categories

Resources