Skip to content

Instantly share code, notes, and snippets.

@Slach
Created October 28, 2017 08:22
Show Gist options
  • Save Slach/6804b21209739b1acd8e57a971743017 to your computer and use it in GitHub Desktop.
Save Slach/6804b21209739b1acd8e57a971743017 to your computer and use it in GitHub Desktop.
Metrica Logs API wrong escaping Array(String) fields
ym:s:productsPurchaseID ym:s:productsCategory ym:s:productsCurrency ym:s:visitID ym:s:UTMContent ym:s:openstatCampaign ym:s:impressionsProductCoupon ym:s:dateTime ym:s:lastDirectConditionType ym:s:browserEngineVersion3 ym:s:browserEngineVersion1 ym:s:browserEngineVersion2 ym:s:UTMMedium ym:s:hasGCLID ym:s:productsCategory1 ym:s:impressionsProductCategory4 ym:s:productsID ym:s:productsVariant ym:s:screenColors ym:s:windowClientHeight ym:s:impressionsProductID ym:s:impressionsProductName ym:s:lastReferalSource ym:s:browserEngine ym:s:physicalScreenHeight ym:s:watchIDs ym:s:screenHeight ym:s:purchaseRevenue ym:s:purchaseShipping ym:s:productsCategory3 ym:s:networkType ym:s:deviceCategory ym:s:screenWidth ym:s:lastSearchEngine ym:s:UTMSource ym:s:operatingSystem ym:s:flashMajor ym:s:windowClientWidth ym:s:productsPrice ym:s:isNewUser ym:s:goalsID ym:s:impressionsProductCategory1 ym:s:impressionsProductCurrency ym:s:ipAddress ym:s:productsBrand ym:s:impressionsURL ym:s:lastSocialNetworkProfile ym:s:browserLanguage ym:s:browserMinorVersion ym:s:purchaseDateTime ym:s:impressionsDateTime ym:s:impressionsProductCategory3 ym:s:lastDirectPlatform ym:s:UTMCampaign ym:s:impressionsProductBrand ym:s:lastAdvEngine ym:s:productsCategory5 ym:s:purchaseCoupon ym:s:clientTimeZone ym:s:bounce ym:s:goalsPrice ym:s:javascriptEnabled ym:s:openstatService ym:s:flashMinor ym:s:productsCategory2 ym:s:pageViews ym:s:UTMTerm ym:s:operatingSystemRoot ym:s:screenFormat ym:s:counterID ym:s:regionCountry ym:s:purchaseID ym:s:lastDirectBannerGroup ym:s:lastDirectPhraseOrCond ym:s:openstatSource ym:s:screenOrientation ym:s:purchaseTax ym:s:lastDirectClickBannerName ym:s:goalsSerialNumber ym:s:lastSearchEngineRoot ym:s:purchaseAffiliation ym:s:lastDirectPlatformType ym:s:mobilePhone ym:s:lastDirectClickOrderName ym:s:lastDirectClickBanner ym:s:browserMajorVersion ym:s:lastDirectClickOrder ym:s:browserEngineVersion4 ym:s:physicalScreenWidth ym:s:goalsOrder ym:s:lastSocialNetwork ym:s:openstatAd ym:s:productsPosition ym:s:impressionsProductCategory2 ym:s:cookieEnabled ym:s:impressionsProductCategory ym:s:clientID ym:s:regionCity ym:s:browserCountry ym:s:productsCoupon ym:s:productsQuantity ym:s:impressionsProductCategory5 ym:s:endURL ym:s:visitDuration ym:s:goalsDateTime ym:s:lastTrafficSource ym:s:referer ym:s:lastCurrencyID ym:s:dateTimeUTC ym:s:startURL ym:s:date ym:s:purchaseProductQuantity ym:s:productsCategory4 ym:s:purchaseCurrency ym:s:productsName ym:s:impressionsProductVariant ym:s:lastClickBannerGroupName ym:s:mobilePhoneModel ym:s:browser ym:s:params ym:s:from ym:s:goalsCurrency ym:s:impressionsProductPrice
[] [] [] 5371442163254824646 [] 2017-09-14 08:47:05 0 537 36 0 [] [] [] [] 24 1014 [] [] WebKit 1080 [5371442163254824646,5371839569938874493,5371851824488784617,5371929612480684761,5371930352652919547,5371968114080354003,5371968811075374800] 1080 [] [] [] 1 1920 windows_7_2008server 0 1837 [] 1 [24345998] [] [] 37.113.163.xxx [] [] 30066 0 [] [] [] [] ya_undefined [] [] 300 0 [0] 1 0 [] 7 windows 37 40327473 Russia [] 0 2 [] 0 [1] [] 0 0 60 0 1920 [\'\'] [] [] 1 [] 1505360822455432564 Chelyabinsk 0 [] [] [] http://apollon174.ru/actions/besplatnaya-konsultaciya-kosmetologa/ 2009 [\'2017-09-14 07:13:08\'] direct 2017-09-14 06:47:05 http://apollon174.ru/directions/uzi/ 2017-09-14 [] [] [] [] [] chrome [] [] []
import csv
with open('metrika_visits.1.tsv') as tsvfile:
reader = csv.DictReader(tsvfile, delimiter='\t', quoting=csv.QUOTE_NONE)
for row in reader:
print row['ym:s:goalsDateTime']
print row['ym:s:goalsOrder']
"""
will output
[\'2017-09-14 07:13:08\']
[\'\']
but much better if it will be without quotes
['2017-09-14 07:13:08']
['']
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment