View Category
Check your language appears on the langref.org site
Your language name should appear within the HTML found at the http:
//langreg.org main page.
python
from urllib import urlopen
print urlopen('http://langref.org').read().find('python') >= 0 and 'found' or 'not found'
print urlopen('http://langref.org').read().find('python') >= 0 and 'found' or 'not found'
fsharp
let httpReq = (WebRequest.Create(url) :?> HttpWebRequest)
httpReq.KeepAlive <- false
let httpStream = new StreamReader(httpReq.GetResponse().GetResponseStream())
let htmlPage = httpStream.ReadToEnd()
httpStream.Close()
let offerStatus = (if (htmlPage.IndexOf(url ^ language) > 0) then "offers" ; else "does not offer")
Console.WriteLine("{0} {1} {2}", url, offerStatus, language)
httpReq.KeepAlive <- false
let httpStream = new StreamReader(httpReq.GetResponse().GetResponseStream())
let htmlPage = httpStream.ReadToEnd()
httpStream.Close()
let offerStatus = (if (htmlPage.IndexOf(url ^ language) > 0) then "offers" ; else "does not offer")
Console.WriteLine("{0} {1} {2}", url, offerStatus, language)
Send an email
Use library functions, classes or objects to create a short email addressed to your own email address. The subject should be,
"Greetings from langref.org", and the user should be prompted for the message body, and whether to cancel or proceed with sending the email.
python
import smtplib
import locale
from email.mime.text import MIMEText
encoding = locale.getpreferredencoding()
def main():
smtp_servername = "smtp.example.com"
from_addr = "ernie@example.com"
to_addr = "cookie.monster@mailinator.com"
body = raw_input("Enter the email message ")
if not raw_input("Send email? y/N ") in ["y", "Y"]:
print "aborting"
return
message = MIMEText(body, _charset=encoding)
message["From"] = from_addr
message["To"] = to_addr
message["Subject"] = "Greetings from langref.org"
server = smtplib.SMTP(smtp_servername)
server.sendmail(from_addr, to_addr, message.as_string())
if __name__ == "__main__":
main()
import locale
from email.mime.text import MIMEText
encoding = locale.getpreferredencoding()
def main():
smtp_servername = "smtp.example.com"
from_addr = "ernie@example.com"
to_addr = "cookie.monster@mailinator.com"
body = raw_input("Enter the email message ")
if not raw_input("Send email? y/N ") in ["y", "Y"]:
print "aborting"
return
message = MIMEText(body, _charset=encoding)
message["From"] = from_addr
message["To"] = to_addr
message["Subject"] = "Greetings from langref.org"
server = smtplib.SMTP(smtp_servername)
server.sendmail(from_addr, to_addr, message.as_string())
if __name__ == "__main__":
main()
fsharp
open System
open System.Net
open System.Net.Mail
open System.Net.Mime
let subject = "Greetings from langref.org"
let from = "username@gmail.com"
let destination = "username@gmail.com"
printfn "Write mail body (press 'Enter' when finished):"
let mutable body = Console.ReadLine()
if body = null || body.Length = 0 then
body <- "Hello World"
let mail = new MailMessage(from, destination, subject, body)
let smtpHost = "smtp.gmail.com"
let clientCredentials = new NetworkCredential("username@gmail.com", "password")
let smtpClient = new SmtpClient(smtpHost,587)
smtpClient.EnableSsl <- true
smtpClient.UseDefaultCredentials <- false
smtpClient.Credentials <- clientCredentials
printfn "Send email? y/n"
match Console.ReadLine() with
| "y" -> smtpClient.Send(mail);mail.Dispose();printfn "email delivered"
| "n" -> smtpClient.Dispose()
| _ -> smtpClient.Dispose()
open System.Net
open System.Net.Mail
open System.Net.Mime
let subject = "Greetings from langref.org"
let from = "username@gmail.com"
let destination = "username@gmail.com"
printfn "Write mail body (press 'Enter' when finished):"
let mutable body = Console.ReadLine()
if body = null || body.Length = 0 then
body <- "Hello World"
let mail = new MailMessage(from, destination, subject, body)
let smtpHost = "smtp.gmail.com"
let clientCredentials = new NetworkCredential("username@gmail.com", "password")
let smtpClient = new SmtpClient(smtpHost,587)
smtpClient.EnableSsl <- true
smtpClient.UseDefaultCredentials <- false
smtpClient.Credentials <- clientCredentials
printfn "Send email? y/n"
match Console.ReadLine() with
| "y" -> smtpClient.Send(mail);mail.Dispose();printfn "email delivered"
| "n" -> smtpClient.Dispose()
| _ -> smtpClient.Dispose()
