Showing posts with label api. Show all posts
Showing posts with label api. Show all posts

Monday, October 5, 2015

MongoDB New CRUD API


The new mongodb shell includes new CRUD API! In addition to the old insert, update, and remove, the shell now supports insertMany, replaceOne, and a variety of other new methods.

> // the old insert API
> db.test.insert({_id: 1})
WriteResult({ "nInserted" : 1 })
> db.test.insert([{_id: 2}, {_id: 3}, {_id: 4}])
BulkWriteResult({
    "writeErrors" : [ ],
    "writeConcernErrors" : [ ],
    "nInserted" : 3,
    "nUpserted" : 0,
    "nMatched" : 0,
    "nModified" : 0,
    "nRemoved" : 0,
    "upserted" : [ ]
})
The new API better distinguishes single- and bulk-insert, and returns more useful results:
> // the new CRUD API
> db.test2.insertOne({_id: 1})
{
    "acknowledged" : true,
    "insertedId" : 1
}
> db.test2.insertMany([{_id: 2}, {_id: 3}, {_id: 4}])
{ 
    "acknowledged" : true,
    "insertedIds" : [ 2, 3, 4 ]
}

> // the old update API
> db.test.update(
... {_id: 1},
... {$set: {x: 1}},
... true              /* upsert */,
... false             /* multi */
)
WriteResult({
    "nMatched" : 0,
    "nUpserted" : 1,
    "nModified" : 0,
    "_id" : 1
})

> // the new update API
> db.test2.updateOne(
... {_id: 1},
... {$set: {x: 1}},
... {upsert: true}
)
{
    "acknowledged" : true,
    "matchedCount" : 0,
    "modifiedCount" : 0,
    "upsertedId" : 1
}

> // the old replace API
> db.test.update(
... {_id: 1},
... {set: {x: 1}}  // OOPS!!
)
WriteResult({
    "nMatched" : 1,
    "nUpserted" : 0,
    "nModified" : 1
})
> // document was replaced
> db.test.findOne()
{ "_id" : 1, "set" : { "x" : 1 } }


> // the old delete API
> db.test.remove({})  // remove EVERYTHING!!

> // the new delete API
> db.test2.deleteOne({})
{ "acknowledged" : true, "deletedCount" : 1 }
> db.test2.deleteMany({})
{ "acknowledged" : true, "deletedCount" : 3 }
Read more on 
https://www.mongodb.com/blog/post/consistent-crud-api-next-generation-mongodb-drivers

Monday, October 31, 2011

Term Extraction with Yahoo Api


Aslında bir kaç kez kapatıldı ve açıldı bu proje [1]. Şimdi günde ip başına  5.000 request sınırlama ile gayet güzel çalışıyor. Yahoo Term Extractor aslında temel amacı verdiğiniz bir metini etiketlemek.

Bir test yaptım 1000 karakterlik bir Türkçe metni 5000 defa gönderdim ve ortalama cevap süresi genellikle 0.5 sn ile 0.4 sn arasındaydı.


1. http://developer.yahoo.com/search/content/V1/termExtraction.html

Friday, September 30, 2011

The IMDB Api

IMDB gibi bir data cevherinin api'sinin olmaması tam anlamıyla bir facia. Datalarını kullanmamız için sunduğu metot ise daha da çileden çıkarıcı http://www.imdb.com/interfaces#plain

Third party bir api olarak bunu [http://www.deanclatworthy.com/imdb/] buldum.
Şimdilik işe yarıyor ama ben şu an sadece api görevi görecek ve old school tekniklerle imdb search, movie, artist sayfalarından regexle data alacak bir class yapıp kendi üst apimi yapmayı düşünüyorum.

Tuesday, August 23, 2011

delicious apisi ile link tagliyorum

delicious'un son durumunu bilmiyorum, kapanacak mı ne zaman kapanacak emin değilim ama elimdeki bazı linkleri onunla tagliyorum
Aşağıdaki official apisi bana bunu sağlıyor
http://feeds.delicious.com/v2/json/urlinfo/data?url=http://www.webrazzi.com

[
{
"hash":"b41ae64e2e80ba1806245c61179ad903",
"title":"Webrazzi",
"url":"http:\/\/www.webrazzi.com\/",
"total_posts":209,
"top_tags":
   {"blog":77,"web2.0":54,"internet":36,"web":33,"technology":29,"webrazzi":23,"news":19,"haber":17,"blogs":14,"webdesign":13}
}
]

Thursday, August 18, 2011

Google Profanity ile istenmeyen kelime filtreleme meselesi

wdyl.com açılalı epey oldu. wdyl altında bir basit servis ve google'ın resmi bir apisi olan profanity api ile bir kelimenin istenmeyen ifade olup olmadığını anlayabilirsiniz.
"xxx"
"porno"
gibi ifadeler

Kullanımı basit
http://www.wdyl.com/profanity?q=ankara
"q" parametresine kelimenizi verin "true" veya "false" alacaksınız. "true" olması istenmeyen bir kelime olması demektir.
örnek çıktı (json formatında veriyor)

http://www.wdyl.com/profanity?q=ankara
{"response": "false"}


http://www.wdyl.com/profanity?q=porno
{"response": "true"}


As Wade notes, a simple snippet of PHP code can be used with apps via a JSON call to query whether or not Google thinks any given text contains rude words.
meseleyi irdeleyin http://labs.phurix.net/posts/googles-official-profanity-api


Tuesday, July 5, 2011

Google Suggest Api

Aslında official olarak bir api değil.
Şu şekilde epey kullandım
http://www.google.com/complete/search?hl=tr&client=suggest&js=true&q=test

hl parametresi dil ayarıdır.

Bir kaç gündür test ediyorum ve fark sanırım bir gün için bir ip'ye 50.000 sorgu kadar limit verilmiş. Çünkü artık 403 hatası vermeye başladı.

Ayrıca Yahoo suggest de var o ise günlük bir IP'ye 5.000 sorgu limiti veriyor ve google kadar güzel sonuclar vermiyor

Thursday, March 11, 2010

Google Visualization Api - Interactive charts ve UTF-8 Karakter Sorunu

Visualization Api içinde "Interactive charts" son derece pratik ve gelişmiş bir şekilde grafik sunum ihtiyaçlarınızı karşılıyor. "Image Charts" için herhangi bir js kütüphanesi yüklemenize gerek olmazken bunda Google jsapi ile Visualization Api yi yükletiyorsunuz sayfanıza. Detay : http://code.google.com/apis/visualization/documentation/using_overview.html

Ben de harita üzerinden ağırlık dağılımını göstermek için kullandım şu şekilde

<script type="text/javascript" charset="utf-8" src="http://www.google.com/jsapi">
</script>
<script type="text/javascript" charset="utf-8">
    google.load('visualization', '1', {
        'packages': ['geomap']
    });
    var temp = 0;
    google.setOnLoadCallback(drawMap);


    function drawMap() {

        var data = new google.visualization.DataTable();
        data.addRows(81);
        data.addColumn('string', 'City');
        data.addColumn('number', 'Kelime Sayisi');

// ...
        data.setValue(4, 0, 'İstanbul');
        data.setValue(4, 1, 57);

        data.setValue(5, 0, 'Ankara');
        data.setValue(5, 1, 42);
// ...

var options = {};
   options['region'] = 'TR';
   options['colors'] = [0xA493FF, 0x4C51CD, 0x00065E]; // colors
   options['dataMode'] = 'regions';
   options['width'] = '540px';
   options['height'] = '348px';
 
   var container = document.getElementById('map_canvas');
   var geomap = new google.visualization.GeoMap(container); 
  
   var ikinci_sehir="";
   var ilk_sehir="";
   
  google.visualization.events.addListener(geomap, 'regionClick', function(e) {   
   sehir=e['region']; // tıklanan sehri su sekilde getirir : TR-06   : TR-PLAKA  
 });
 
 geomap.draw(data, options);
 
    };


Çok da güzel oldu aslında.



Fakat tek sorun Türkçe karakterlerde.
Tam şurada şehir adlarını eklediğim yerde :
  
        data.setValue(4, 0, 'İstanbul');
        data.setValue(4, 1, 57);
        data.setValue(5, 0, 'Ankara');
        data.setValue(5, 1, 42);

Bu grafiğin aynısı google analytics'de de var ve fakat orada Türkçe karakter sorunu yok. Yani çözümsüz bir şey değil fakat henüz çözüm bulamadım.

Mesela neler yaptığımı da yazayım, "şunu yap bunu yap öyle dene" demeyin yani :

1. Sayfanın karakter kodlaması gerçekten de UTF-8 mi diye kontrol ettim
2. header ('Content-type: text/html; charset=utf-8'); yaptım üstüne bir de
3. javascript tagına charset="utf-8" ekledim
4. google jsapi'ye karakter kodlaması parametresini utf-8 verdim bir d eöyle yüklettim
5. Gelen şehir isimleri "string" değerlerimi veritabanından doğrumu çekiyorum
6. iconv ile utf-8 gelen şehir adlarını bir de iso formatına çevirdim.
7. 6 dakininin tam tersini yaptım
8. bıktım usandm bıraktım
9. google araması yaptım
10. uykum geldi bu yazıyı yazdım


Çözüm bulur bulmaz yazacağım buraya. Fakat lurda okuyan bir bilinçli internet kullanıcısı çözümü biliyorsa yorum olarak yazsa ne güzel olur?