"""
   Returns a replicated fgdb from AGOL
   attachments are included in the fgdb
"""
from arcrest.agol import featureservice
if __name__ == "__main__":
    try:

        username = ""
        password = ""
        url = ""
        print 'test'
        fs = featureservice.FeatureService(url,
                                           username=username,
                                           password=password)
        print fs.createReplica(replicaName="test_replica",
                               layers="0",
                               returnAttachments=True,
                               outputFormat="filegdb",
                               out_path=r"c:\temp")

    except ValueError, e:
        print e
"""
   Queries a feature service and returns the feature count
"""
from arcrest.agol import featureservice, filters

if __name__ == "__main__":
    url = "http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/World_Urban_Areas/FeatureServer"
    fs = featureservice.FeatureService(url=url)
    lds = filters.LayerDefinitionFilter()
    lds.addFilter(layer_id=0, where="FID <= 100")
    print fs.query(layerDefsFilter=lds, returnCountOnly=True)