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'
cpp
HttpWebRequest^ httpReq = safe_cast<HttpWebRequest^>(WebRequest::Create(url)); httpReq->KeepAlive = false;
StreamReader^ httpStream = gcnew StreamReader(httpReq->GetResponse()->GetResponseStream());
String^ htmlPage = httpStream->ReadToEnd(); httpStream->Close();
Console::WriteLine("{0} {1} {2}", url, (htmlPage->IndexOf(url + language) > 0 ? "offers" : "does not offer"), language);
StreamReader^ httpStream = gcnew StreamReader(httpReq->GetResponse()->GetResponseStream());
String^ htmlPage = httpStream->ReadToEnd(); httpStream->Close();
Console::WriteLine("{0} {1} {2}", url, (htmlPage->IndexOf(url + language) > 0 ? "offers" : "does not offer"), language);
clojure
(def *url* "http://langref.org/")
(def *lang* "clojure")
(with-open [ stream (.openStream (URL. *url*)) ]
(let [ body (str (line-seq (BufferedReader. (InputStreamReader. stream)))) ]
(str "Language " *lang* " does "
(if-not (re-matches (re-pattern (str ".*" *url* *lang* ".*")) body) "not ")
"exist")))
(def *lang* "clojure")
(with-open [ stream (.openStream (URL. *url*)) ]
(let [ body (str (line-seq (BufferedReader. (InputStreamReader. stream)))) ]
(str "Language " *lang* " does "
(if-not (re-matches (re-pattern (str ".*" *url* *lang* ".*")) body) "not ")
"exist")))
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()
