Best Python code snippet using localstack_python
create_coalition_view.py
Source:create_coalition_view.py  
...13#--------------------------------14#--------------------------------15def create_views(db):16    # Melbourne17    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("melbourne")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'18    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_melbourne_2020', count_map,19                                         stale='update_after')20    view.sync(db)21    # Sydney22    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("sydney")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'23    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_sydney_2020', count_map,24                                         stale='update_after')25    view.sync(db)26    # adelaide27    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("adelaide")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'28    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_adelaide_2020', count_map,29                                         stale='update_after')30    view.sync(db)31    # brisbane32    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("brisbane")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'33    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_brisbane_2020', count_map,34                                         stale='update_after')35    view.sync(db)36    # canberra37    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("canberra")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'38    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_canberra_2020', count_map,39                                         stale='update_after')40    view.sync(db)41    # darwin42    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("darwin")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'43    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_darwin_2020', count_map,44                                         stale='update_after')45    view.sync(db)46    # hobart47    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("hobart")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'48    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_hobart_2020', count_map,49                                         stale='update_after')50    view.sync(db)51    # perth52    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("perth")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'53    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_perth_2020', count_map,54                                         stale='update_after')55    view.sync(db)56    # Melbourne57    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("melbourne")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'58    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_melbourne_2019', count_map,59                                         stale='update_after')60    view.sync(db)61    # Sydney62    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("sydney")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'63    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_sydney_2019', count_map,64                                         stale='update_after')65    view.sync(db)66    # adelaide67    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("adelaide")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'68    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_adelaide_2019', count_map,69                                         stale='update_after')70    view.sync(db)71    # brisbane72    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("brisbane")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'73    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_brisbane_2019', count_map,74                                         stale='update_after')75    view.sync(db)76    # canberra77    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("canberra")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'78    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_canberra_2019', count_map,79                                         stale='update_after')80    view.sync(db)81    # darwin82    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("darwin")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'83    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_darwin_2019', count_map,84                                         stale='update_after')85    view.sync(db)86    # hobart87    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("hobart")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'88    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_hobart_2019', count_map,89                                         stale='update_after')90    view.sync(db)91    # perth92    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("perth")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'93    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_perth_2019', count_map,94                                         stale='update_after')95    view.sync(db)96    # Melbourne97    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("melbourne")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'98    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_melbourne_2018', count_map,99                                         stale='update_after')100    view.sync(db)101    # Sydney102    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("sydney")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'103    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_sydney_2018', count_map,104                                         stale='update_after')105    view.sync(db)106    # adelaide107    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("adelaide")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'108    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_adelaide_2018', count_map,109                                         stale='update_after')110    view.sync(db)111    # brisbane112    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("brisbane")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'113    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_brisbane_2018', count_map,114                                         stale='update_after')115    view.sync(db)116    # canberra117    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("canberra")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'118    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_canberra_2018', count_map,119                                         stale='update_after')120    view.sync(db)121    # darwin122    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("darwin")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'123    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_darwin_2018', count_map,124                                         stale='update_after')125    view.sync(db)126    # hobart127    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("hobart")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'128    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_hobart_2018', count_map,129                                         stale='update_after')130    view.sync(db)131    # perth132    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("perth")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'133    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_perth_2018', count_map,134                                         stale='update_after')135    view.sync(db)136    # Melbourne137    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("melbourne")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'138    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_melbourne_2017', count_map,139                                         stale='update_after')140    view.sync(db)141    # Sydney142    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("sydney")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'143    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_sydney_2017', count_map,144                                         stale='update_after')145    view.sync(db)146    # adelaide147    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("adelaide")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'148    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_adelaide_2017', count_map,149                                         stale='update_after')150    view.sync(db)151    # brisbane152    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("brisbane")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'153    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_brisbane_2017', count_map,154                                         stale='update_after')155    view.sync(db)156    # canberra157    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("canberra")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'158    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_canberra_2017', count_map,159                                         stale='update_after')160    view.sync(db)161    # darwin162    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("darwin")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'163    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_darwin_2017', count_map,164                                         stale='update_after')165    view.sync(db)166    # hobart167    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("hobart")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'168    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_hobart_2017', count_map,169                                         stale='update_after')170    view.sync(db)171    # perth172    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("perth")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'173    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_perth_2017', count_map,174                                         stale='update_after')175    view.sync(db)176    # Melbourne177    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("melbourne")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'178    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_melbourne_2016', count_map,179                                         stale='update_after')180    view.sync(db)181    # Sydney182    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("sydney")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'183    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_sydney_2016', count_map,184                                         stale='update_after')185    view.sync(db)186    # adelaide187    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("adelaide")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'188    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_adelaide_2016', count_map,189                                         stale='update_after')190    view.sync(db)191    # brisbane192    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("brisbane")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'193    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_brisbane_2016', count_map,194                                         stale='update_after')195    view.sync(db)196    # canberra197    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("canberra")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'198    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_canberra_2016', count_map,199                                         stale='update_after')200    view.sync(db)201    # darwin202    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("darwin")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'203    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_darwin_2016', count_map,204                                         stale='update_after')205    view.sync(db)206    # hobart207    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("hobart")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'208    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_hobart_2016', count_map,209                                         stale='update_after')210    view.sync(db)211    # perth212    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("liberal") || doc.full_text.toLowerCase().includes("national") || doc.full_text.toLowerCase().includes("coalition")) && (doc.user.location.toLowerCase().includes("perth")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'213    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'coalition_perth_2016', count_map,214                                         stale='update_after')215    view.sync(db)216#--------------------------------217#--------------------------------218if __name__=="__main__":219    couchdb_ip = os.getenv('couchdb_ip')220    couchdb_user = os.getenv('couchdb_user')221    couchdb_pass = os.getenv('couchdb_pass')222    couch = couchdb.Server('http://' + couchdb_user + ':' + couchdb_pass + '@' + couchdb_ip + ':5984/')223    db = couch['twitter_stream_listener'] # existing224    create_views(db)...create_labour_view.py
Source:create_labour_view.py  
...13#--------------------------------14#--------------------------------15def create_views(db):16    #Melbourne17    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("melbourne")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'18    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_melbourne_2020', count_map,19                                         stale='update_after')20    view.sync(db)21    # sydney22    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("sydney")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'23    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_sydney_2020', count_map,24                                         stale='update_after')25    view.sync(db)26    # adelaide27    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("adelaide")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'28    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_adelaide_2020', count_map,29                                         stale='update_after')30    view.sync(db)31    # brisbane32    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("brisbane")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'33    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_brisbane_2020', count_map,34                                         stale='update_after')35    view.sync(db)36    # canberra37    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("canberra")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'38    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_canberra_2020', count_map,39                                         stale='update_after')40    view.sync(db)41    # darwin42    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("darwin")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'43    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_darwin_2020', count_map,44                                         stale='update_after')45    view.sync(db)46    # hobart47    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("hobart")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'48    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_hobart_2020', count_map,49                                         stale='update_after')50    view.sync(db)51    # perth52    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("perth")) && (doc.created_at.split(" ").pop() == "2020")) {emit(doc.full_text);}}'53    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_perth_2020', count_map, stale='update_after')54    view.sync(db)55    #Melbourne56    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("melbourne")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'57    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_melbourne_2019', count_map,58                                         stale='update_after')59    view.sync(db)60    # sydney61    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("sydney")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'62    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_sydney_2019', count_map,63                                         stale='update_after')64    view.sync(db)65    # adelaide66    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("adelaide")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'67    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_adelaide_2019', count_map,68                                         stale='update_after')69    view.sync(db)70    # brisbane71    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("brisbane")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'72    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_brisbane_2019', count_map,73                                         stale='update_after')74    view.sync(db)75    # canberra76    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("canberra")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'77    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_canberra_2019', count_map,78                                         stale='update_after')79    view.sync(db)80    # darwin81    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("darwin")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'82    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_darwin_2019', count_map,83                                         stale='update_after')84    view.sync(db)85    # hobart86    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("hobart")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'87    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_hobart_2019', count_map,88                                         stale='update_after')89    view.sync(db)90    # perth91    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("perth")) && (doc.created_at.split(" ").pop() == "2019")) {emit(doc.full_text);}}'92    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_perth_2019', count_map, stale='update_after')93    view.sync(db)94    #Melbourne95    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("melbourne")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'96    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_melbourne_2018', count_map,97                                         stale='update_after')98    view.sync(db)99    # sydney100    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("sydney")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'101    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_sydney_2018', count_map,102                                         stale='update_after')103    view.sync(db)104    # adelaide105    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("adelaide")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'106    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_adelaide_2018', count_map,107                                         stale='update_after')108    view.sync(db)109    # brisbane110    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("brisbane")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'111    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_brisbane_2018', count_map,112                                         stale='update_after')113    view.sync(db)114    # canberra115    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("canberra")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'116    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_canberra_2018', count_map,117                                         stale='update_after')118    view.sync(db)119    # darwin120    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("darwin")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'121    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_darwin_2018', count_map,122                                         stale='update_after')123    view.sync(db)124    # hobart125    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("hobart")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'126    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_hobart_2018', count_map,127                                         stale='update_after')128    view.sync(db)129    # perth130    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("perth")) && (doc.created_at.split(" ").pop() == "2018")) {emit(doc.full_text);}}'131    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_perth_2018', count_map, stale='update_after')132    view.sync(db)133    #Melbourne134    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("melbourne")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'135    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_melbourne_2017', count_map,136                                         stale='update_after')137    view.sync(db)138    # sydney139    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("sydney")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'140    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_sydney_2017', count_map,141                                         stale='update_after')142    view.sync(db)143    # adelaide144    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("adelaide")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'145    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_adelaide_2017', count_map,146                                         stale='update_after')147    view.sync(db)148    # brisbane149    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("brisbane")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'150    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_brisbane_2017', count_map,151                                         stale='update_after')152    view.sync(db)153    # canberra154    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("canberra")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'155    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_canberra_2017', count_map,156                                         stale='update_after')157    view.sync(db)158    # darwin159    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("darwin")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'160    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_darwin_2017', count_map,161                                         stale='update_after')162    view.sync(db)163    # hobart164    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("hobart")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'165    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_hobart_2017', count_map,166                                         stale='update_after')167    view.sync(db)168    # perth169    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("perth")) && (doc.created_at.split(" ").pop() == "2017")) {emit(doc.full_text);}}'170    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_perth_2017', count_map, stale='update_after')171    view.sync(db)172    #Melbourne173    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("melbourne")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'174    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_melbourne_2016', count_map,175                                         stale='update_after')176    view.sync(db)177    # sydney178    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("sydney")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'179    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_sydney_2016', count_map,180                                         stale='update_after')181    view.sync(db)182    # adelaide183    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("adelaide")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'184    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_adelaide_2016', count_map,185                                         stale='update_after')186    view.sync(db)187    # brisbane188    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("brisbane")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'189    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_brisbane_2016', count_map,190                                         stale='update_after')191    view.sync(db)192    # canberra193    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("canberra")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'194    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_canberra_2016', count_map,195                                         stale='update_after')196    view.sync(db)197    # darwin198    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("darwin")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'199    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_darwin_2016', count_map,200                                         stale='update_after')201    view.sync(db)202    # hobart203    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("hobart")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'204    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_hobart_2016', count_map,205                                         stale='update_after')206    view.sync(db)207    # perth208    count_map = 'function(doc) { if((doc.full_text.toLowerCase().includes("labor") || doc.full_text.toLowerCase().includes("alp")) && (doc.user.location.toLowerCase().includes("perth")) && (doc.created_at.split(" ").pop() == "2016")) {emit(doc.full_text);}}'209    view = couchdb.design.ViewDefinition('twitter_stream_listener', 'labor_perth_2016', count_map, stale='update_after')210    view.sync(db)211#--------------------------------212#--------------------------------213if __name__=="__main__":214    couchdb_ip = os.getenv('couchdb_ip')215    couchdb_user = os.getenv('couchdb_user')216    couchdb_pass = os.getenv('couchdb_pass')217    couch = couchdb.Server('http://' + couchdb_user + ':' + couchdb_pass + '@' + couchdb_ip + ':5984/')218    db = couch['twitter_stream_listener'] # existing219    create_views(db)...expressions.py
Source:expressions.py  
1# For now, this is limited to compound labels using the python or VB syntax2def convertExpression(expression, tolowercase):3    if tolowercase:4        expression = expression.lower()5    if "+" in expression or "&" in expression:6        if "+" in expression:7            tokens = expression.split("+")[::-1]8        else:9            tokens = expression.split("&")[::-1]10        addends = []11        for token in tokens:12            if "[" in token:13                addends.append(["PropertyName", token.replace("[", "").replace("]", "").strip()])14            else:15                addends.append(token.replace('"', ''))16            allOps = addends[0]17            for attr in addends[1:]:18                allOps = ["Concatenate", attr, allOps]19        expression = allOps20    else:21        expression = ["PropertyName", expression.replace("[", "").replace("]", "")]22    return expression23def stringToParameter(s, tolowercase):24    s = s.strip()25    if "'" in s or '"' in s:26        return s.strip("'\"")27    else:28        s = s.lower() if tolowercase else s29        return ["PropertyName", s]30# For now, limited to = or IN statements31# There is no formal parsing, just a naive conversion32def convertWhereClause(clause, tolowercase):33    if "=" in clause:34        tokens = clause.split("=")35        expression = ["PropertyIsEqualTo",36                      stringToParameter(tokens[0], tolowercase),37                      stringToParameter(tokens[1], tolowercase)]38        return expression39    elif " in " in clause.lower():40        clause = clause.replace(" IN ", " in ")41        tokens = clause.split(" in ")42        attribute = tokens[0]43        values = tokens[1].strip("() ").split(",")44        subexpressions = []45        for v in values:46            subexpressions.append(["PropertyIsEqualTo",47                                  stringToParameter(attribute, tolowercase),48                                  stringToParameter(v, tolowercase)])49        expression = []50        if len(values) == 1:51            return subexpressions[0]52        else:53            accum = ["Or", subexpressions[0], subexpressions[1]]54            for subexpression in subexpressions[2:]:55                accum = ["Or", accum, subexpression]56            return accum...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
