Automatic reading of virtual currency quotes and reminders of gadgets (Mac OSX)

Source: Internet
Author: User

ImportJava.io.BufferedReader;ImportJava.io.InputStream;ImportJava.io.InputStreamReader;Importjava.net.HttpURLConnection;ImportJava.net.URL;Importjava.io.IOException; Public classprice{ Public StaticString url_prefix = "https://trade.chbtc.com/api/";  Public StaticString Api_domain = "http://api.chbtc.com";  Public Static floatEtcprice = 0;  Public Static Booleannoticed =false;  Public StaticString win = "You are rich, you are rich, you are rich, you rich, you rich, you rich, you rich, you rich, you rich, you rich, you rich, you rich, you rich, you rich, you rich, you rich, you wealthy, you rich, you rich, you are rich, , you are rich, you are rich, you are rich, you are rich, ";  Public StaticString lose = "To compensate for crying, to compensate for crying, to compensate for crying, to compensate for crying, to compensate for crying, to compensate for crying, to compensate for crying, to compensate for crying, to compensate for crying, to compensate for crying, to compensate for crying, to compensate for crying, to compensate for crying, to compensate for crying, to compensate for crying, to pay the tears, to compensate for crying, to compensate for crying, To compensate for crying, to compensate for crying, to compensate for crying, ";  Public Static voidMain (String []args) {Try{             while(true) {Testticker ("Btc_cny"); Testticker ("Ltc_cny"); Testticker ("Etc_cny"); Testticker ("Eth_cny"); System.out.println ((int) (742.103 * etcPrice-33200)); //System.out.println ("");                if(!noticed) {                    if((742.103 * etcPrice-33200) > 5000) say (win); Else if((742.103 * etcPrice-33200) < 1000) say (lose); } thread.sleep (5000); }        }Catch(Exception e) {e.printstacktrace (); }    }    /*** Get quotes*/     Public Static voidtestticker (String currency) {Try {            //String currency = "BTC_CNY"; //Request AddressString url = api_domain+ "/data/v1/ticker?currency=" +currency; //Request TestString callback = Get (URL, "UTF-8"); intStart = Callback.indexof ("\" buy\ ": \" "); intEnd = Callback.indexof ("\", \ "High\" "); System.out.print (Currency.substring (0,3) + "" +callback.substring (start+7,end) + "\ T"); if(Currency.equals ("Etc_cny") ) {Etcprice= Float.valueof (callback.substring (start+7, end)); }        } Catch(Exception ex) {ex.printstacktrace (); }    }            /**     *      * @paramUrlall *: Request interface *@paramCharSet *: Character encoding *@returnreturn JSON results*/     Public Staticstring Get (String Urlall, String charset) {BufferedReader reader=NULL; String result=NULL; StringBuffer SBF=NewStringBuffer (); String useragent= "mozilla/5.0 (Windows NT 6.1) applewebkit/537.36 (khtml, like Gecko) chrome/29.0.1547.66 safari/537.36";//Simulation Browser        Try{URL URL=NewURL (Urlall); HttpURLConnection Connection=(httpurlconnection) URL. OpenConnection (); Connection.setrequestmethod ("GET"); Connection.setreadtimeout (30000); Connection.setconnecttimeout (30000); Connection.setrequestproperty ("User-agent", useragent);            Connection.connect (); InputStream is=Connection.getinputstream (); Reader=NewBufferedReader (NewInputStreamReader (IS, CharSet)); String Strread=NULL;  while((Strread = Reader.readline ())! =NULL) {sbf.append (strread); Sbf.append ("\ r \ n");            } reader.close (); Result=sbf.tostring (); } Catch(Exception e) {e.printstacktrace (); }        returnresult; }     Public Static voidsay (String content) {Try             {                //Execute Commandnoticed =true; Runtime.getruntime (). EXEC ("Say \" "+content+" \ ""); }            Catch(IOException e) {e.printstacktrace (); }        }}

Using the CHBTN API, you can voice reminders.

When used directly

Javac Price.java

Java Price

Automatic reading of virtual currency quotes and reminders of gadgets (Mac OSX)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.