-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.py
1 lines (1 loc) · 11.4 KB
/
scraper.py
1
aW1wb3J0IHJlcXVlc3RzLCB1cmxsaWIsIHJlLHRpbWUsIGZyYW1lc2NyYXAsZ2V0cHJveHksanNvbgpmcm9tIGJzNCBpbXBvcnQgQmVhdXRpZnVsU291cApmcm9tIGJhc2U2NCBpbXBvcnQgYjY0ZGVjb2RlIGFzIG9wcwojcmV0dXJucyBsaW5rIGltZ3MgdGl0bGVzCiMjIyMjIyMjIHByb3h5ICMjIyMjIyMjCiMgY2Fsemlubz1nZXRwcm94eS5nZXRwcm94eSh0aXBvPSdzb2NrczUnLG5hemlvbmU9J0ZSJykgI3NvY2tzNSAjcHJvdmFyZSBjb24gcmVxdWVzdHMuU2Vzc2lvbgojIGNhbHppbm89Z2V0cHJveHkuZ2V0cHJveHlzMigpCiMgcHJpbnQoY2FsemlubykKcHJveD17IydodHRwL2h0dHBzIHByb3h5IGlmIHUgaGF2ZSBvbmUKfQojIHByaW50KHByb3gpCgojIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMKIyMjIyMjIyBzb3VyY2VzICMjIyMjIyMjCiMgd2l0aCBvcGVuKCJzb3VyY2VzLmpzb24iKSBhcyBmOgojICAgICBkYXRhID0ganNvbi5sb2FkcyhmLnJlYWQoKSkKIyAgICAgdG9rZW4gPSBkYXRhWyJ0b2tlbiJdCiMgICAgIHVzZXIgPSBkYXRhWyJ1c2VyIl0KCgojIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMgKHRvIGJlIHVwZGF0ZWQgZHVlIHRvIGFuIGhlcm9rdSAmIGNsb3VkZmxhcmUgaXNzdWUpCgpkZWYgZGVjKHN0cmluZ2EpOgogICAgcmV0dXJuIG9wcyhzdHJpbmdhKS5kZWNvZGUoInV0Zi04IikKCmRlZiBhbHRhZGVmZGFuY2UodXJsKToKICAgIGxpbmtzLCBpbWdzLCB0aXRsZXM9W10gLCBbXSAsIFtdCiAgICBzPXJlc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VzCiAgICAgICAgdGl0PWkuZmluZCgnaDMnKQogICAgICAgIHRpdGxlcy5hcHBlbmQodGl0LmdldF90ZXh0KCkpCiAgICByZXR1cm4gbGlua3MsaW1ncyx0aXRsZXMKCmRlZiBndWFyZGFzZXJpZSh1cmwpOgogICAgbGlua3MsIGltZ3MsIHRpdGxlcz1bXSAsIFtdICwgW10KICAgICMgcz1yZXF1ZXN0cy5TZXNzaW9uKCkKICAgICMgcy5wcm94aWVzPXByb3gKICAgICMgcmVxPXMuZ2V0KHVybCkudGV4dAogICAgcmVxPXJlcXVlc3RzLmdldCh1cmwscHJveGllcz1wcm94LGFsbG93X3JlZGlyZWN0cz1UcnVlKS50ZXh0CiAgICBzb3VwID0gQmVhdXRpZnVsU291cChyZXEsICdodG1sLnBhcnNlcicpICMjZGl2IGNsYXNzPWNsYXNzPSJjb2wteHMtNiBjb2wtc20tMi01IgogICAgZm9yIGkgaW4gc291cC5maW5kX2FsbCgiZGl2IiwgY2xhc3NfPSJtbG5oLTIiKToKICAgICAgICB0cnk6CiAgICAgICAgICAgICMjbGlua3MKICAgICAgICAgICAgbGluaz1pLmZpbmQoJ2EnKQogICAgICAgICAgICBsaW5rcy5hcHBlbmQobGluay5nZXQoJ2hyZWYnKSkKICAgICAgICAgICAgIyNpbWcKICAgICAgICAgICAgaW1nPVtdI2kuZmluZCgnaW1nJykKICAgICAgICAgICAgI2ltZ3MuYXBwZW5kKGltZy5nZXQoJ3NyYycpKQogICAgICAgICAgICAjI3RpdGxlcwogICAgICAgICAgICB0aXQ9aS5maW5kKCdhJykKICAgICAgICAgICAgdGl0bGVzLmFwcGVuZCh0aXQuZ2V0X3RleHQoKSkKICAgICAgICBleGNlcHQ6IGNvbnRpbnVlCgogICAgcmV0dXJuIGxpbmtzLGltZ3MsdGl0bGVzCgpkZWYgYWx0YWRlZm5hbWUodXJsKToKICAgIGxpbmtzLCBpbWdzLCB0aXRsZXM9W10gLCBbXSAsIFtdCiAgICByZXE9cmVxdWVzdHMuZ2V0KHVybCxwcm94aWVzPXByb3gpLnRleHQKICAgIHNvdXAgPSBCZWF1dGlmdWxTb3VwKHJlcSwgJ2h0bWwucGFyc2VyJykgIyNkaXYgY2xhc3M9ImNvbC1sZy0zIGNvbC1tZC0zIGNvbC14cy00IgogICAgZm9yIGkgaW4gc291cC5maW5kX2FsbCgiZGl2IiwgY2xhc3NfPSJjb2wtbGctMyBjb2wtbWQtMyBjb2wteHMtNCIpOgogICAgICAgICMjbGlua3MKICAgICAgICBsaW5rPWkuZmluZCgnYScpCiAgICAgICAgbGlua3MuYXBwZW5kKGxpbmsuZ2V0KCdocmVmJykpCiAgICAgICAgIyNpbWcKICAgICAgICBpbWc9aS5maW5kKCdpbWcnKQogICAgICAgIGltZ3MuYXBwZW5kKCdodHRwczovL2FsdGFkZWZpbml6aW9uZS5uYW1lJytpbWcuZ2V0KCdzcmMnKSkKICAgICAgICAjI3RpdGxlcwogICAgICAgIHRpdD1pLmZpbmQoJ2gyJywgY2xhc3NfPSd0aXRsZUZpbG0nKQogICAgICAgIHRpdGxlcy5hcHBlbmQodGl0LmdldF90ZXh0KCkpCgogICAgcmV0dXJuIGxpbmtzLGltZ3MsdGl0bGVzCgpkZWYgY2luZWJsb2dyZWVuKHVybCk6CiAgICBsaW5rcywgaW1ncywgdGl0bGVzPVtdICwgW10gLCBbXQogICAgcmVxPXJlcXVlc3RzLmdldCh1cmwscHJveGllcz1wcm94KS50ZXh0CiAgICBzb3VwID0gQmVhdXRpZnVsU291cChyZXEsICdodG1sLnBhcnNlcicpICMjPGFydGljbGUgY2xhc3M9InNob3J0Ij4KICAgIGZvciBpIGluIHNvdXAuZmluZF9hbGwoImFydGljbGUiLCBjbGFzc189InNob3J0Iik6CiAgICAgICAgIyNsaW5rcwogICAgICAgIGxpbms9aS5maW5kKCdhJykKICAgICAgICBsaW5rcy5hcHBlbmQobGluay5nZXQoJ2hyZWYnKSkKICAgICAgICAjI2ltZwogICAgICAgICNpbWc9aS5maW5kKCdpbWcn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2IGNsYXNzPSBjb250YWluZXItaW5kZXgtcG9zdCBjb2wteHMtNCBjb2wtc20tMyBjb2wtbWQtMi01IGNvbC1sZy0yCiAgICB0cnk6CiAgICAgICAgZm9yIGkgaW4gc291cC5maW5kX2FsbCgiZGl2IiwgY2xhc3NfPSJjb250YWluZXItaW5kZXgtcG9zdCBjb2wteHMtNCBjb2wtc20tMyBjb2wtbWQtMi01IGNvbC1sZy0yIik6CiAgICAgICAgICAgICMjbGlua3MKICAgICAgICAgICAgbGluaz1pLmZpbmQoJ2EnKQogICAgICAgICAgICBsaW5rcy5hcHBlbmQobGluay5nZXQoJ2hyZWYnKSkKICAgICAgICAgICAgIyNpbWcKICAgICAgICAgICAgaW1nPWkuZmluZCgnaW1nJykKICAgICAgICAgICAgaW1ncy5hcHBlbmQoaW1nLmdldCgnc3JjJykpCiAgICAgICAgICAgICMjdGl0bGVzCiAgICAgICAgICAgIHRpdD1pLmZpbmQoJ2gyJykKICAgICAgICAgICAgdGl0bGVzLmFwcGVuZCh0aXQuZ2V0X3RleHQoKSkKICAgIGV4Y2VwdCBFeGNlcHRpb24gYXMgZTogCiAgICAgICAgcHJpbnQoZSkKICAgIHJldHVybiBsaW5rcyxpbWdzLHRpdGxlcwoKZGVmIGRyZWFtc3ViKHVybCk6CiAgICBsaW5rcywgaW1ncywgdGl0bGVzPVtdICwgW10gLCBbXQogICAgcmVxPXJlcXVlc3RzLmdldCh1cmwsdGltZS5zbGVlcCgxNSkscHJveGllcz1wcm94KS50ZXh0CiAgICBzb3VwID0gQmVhdXRpZnVsU291cChyZXEsICdodG1sLnBhcnNlcicpICMjZGl2IGNsYXNzPSBzaG93U3RyZWFtaW5nIHR2QmxvY2sKICAgIAogICAgZm9yIGkgaW4gc291cC5maW5kX2FsbCgiZGl2IiwgY2xhc3NfPSJ0dkJsb2NrIik6CiAgICAgICAgIyNsaW5rcwogICAgICAgIGxpbms9aS5maW5kKCdhJykKICAgICAgICBsaW5rcy5hcHBlbmQoJ2h0dHBzOi8vZHJlYW1zdWIuc3RyZWFtJytsaW5rLmdldCgnaHJlZicpKQogICAgICAgICMjaW1nCiAgICAgICAgaW1nPWkuZmluZCgnZGl2JyxjbGFzc189J2NvdmVyJykKICAgICAgICBpbWc9aW1nLmdldCgnc3R5bGUnKS5yZXBsYWNlKCctLWltYWdlLXVybDp1cmwoLy8nLCdodHRwczovLycpLnJlcGxhY2UoJyknLCcnKQogICAgICAgICMgIyN0aXRsZXMKICAgICAgICB0aXQ9aS5maW5kKCdiJykKICAgICAgICB0aXRsZXMuYXBwZW5kKHRpdC5nZXRfdGV4dCgpKQogICAgCiAgICByZXR1cm4gbGlua3MsaW1ncyx0aXRsZXMKCmRlZiBzZWFyY2godXJsKToKICAgIGEsYixjPVtdLFtdLFtdCiAgICBwcmludCgiU2VhcmNoOiBQcm9jZXNzaW5nICIrdXJsKQogICAgaWYgJ2FsdGFkZWZpbml6aW9uZS5yZXBvcnQnIGluIHVybDogI2RhbmNlCiAgICAgICAgYSxiLGM9IGFsdGFkZWZkYW5jZSh1cmwpCiAgICBlbGlmICdldXJvc3RyZWFtaW5nLnR1YmUnIGluIHVybDogI2NhbXAKICAgICAgICBhLGIsYz0gZXVyb3N0cmNhbXAodXJsKQogICAgZWxpZiAnY2IwMS55b2dhJyBpbiB1cmw6ICNnYW1lcwogICAgICAgIGEsYixjPSBjYjAxZGlyKHVybCkKICAgIGVsaWYgJ2d1YXJkYXNlcmllLmNhbScgaW4gdXJsOiAjZGF0ZQogICAgICAgIGEsYixjPSBndWFyZGFzZXJpZSh1cmwpCiAgICBlbGlmICdhbHRhZGVmaW5pemlvbmUubmFtZScgaW4gdXJsOgogICAgICAgIGEsYixjPSBhbHRhZGVmbmFtZSh1cmwpCiAgICBlbGlmICdjaW5lYmxvZzAxLmJpZCcgaW4gdXJsOgogICAgICAgIGEsYixjPSBjaW5lYmxvZ3JlZW4odXJsKQogICAgZWxpZiAndGFudGlmaWxtLmhvc3QnIGluIHVybDogI2Nvb2wKICAgIC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bz1zZWFyY2gmc3ViYWN0aW9uPXNlYXJjaCcpCiAgICB1cmxzLmFwcGVuZCgnaHR0cHM6Ly93d3cudGFudGlmaWxtLmhvc3Qvc2VhcmNoLycraW5wdXQpICNob3N0CiAgICB1cmxzLmFwcGVuZCgnaHR0cHM6Ly93d3cucGlyYXRlc3RyZWFtaW5nLnZpZGVvLz9zPScraW5wdXQpICNkYXRlCiAgICB1cmxzLmFwcGVuZCgnaHR0cHM6Ly9kcmVhbXN1Yi5zdHJlYW0vc2VhcmNoLz9xPScraW5wdXQpCgogICAgcmV0dXJuIHVybHMKCmRlZiBnbG9iYWxzZWFyY2gobGlzdHVybHMpOgogICAgbD1bXQogICAgaT1bXQogICAgdD1bXQogICAgZm9yIHVybCBpbiBsaXN0dXJsczoKICAgICAgICBhLGIsYz1zZWFyY2godXJsKQogICAgICAgIGZvciB4IGluIGE6bC5hcHBlbmQoeCkKICAgICAgICBmb3IgeCBpbiBiOmkuYXBwZW5kKHgpCiAgICAgICAgZm9yIHggaW4gYzp0LmFwcGVuZCh4KQogICAgcmV0dXJuIGwsaSx0CgpkZWYgZ2xvYmFscHJpbnQodCxsKToKICAgIGk9bGVuKHQpCiAgICBmb3IgciBpbiByYW5nZShpKToKICAgICAgICB0aXRvbG89dFtyXQogICAgICAgIGxpbms9bFtyXQogICAgICAgIHByaW50KCcnK3RpdG9sbysnIC0gJytsaW5rKQogICAgICAgIAoKZGVmIGdsb2JhbHN0cmluZyh0LGwpOgogICAgaT1sZW4odCkKICAgIHJlcz0nJwogICAgZm9yIHIgaW4gcmFuZ2UoaSk6CiAgICAgICAgdGl0b2xvPXRbcl0KICAgICAgICBsaW5rPWxbcl0KICAgICAgICByZXMrPScnK3RpdG9sbysnIC0gJytsaW5rKydcbicKICAgIHJldHVybiByZXMKCmRlZiBnbG9iYWxsaXN0KHQsbCk6CiAgICBpPWxlbih0KQogICAgcmVzPVtdCiAgICBmb3IgciBpbiByYW5nZShpKToKICAgICAgICB0aXRvbG89dFtyXQogICAgICAgIGxpbms9bFtyXQogICAgICAgIGlmIGxlbihsaW5rKT4wOnJlcys9W3RpdG9sbysnIC0gJytsaW5rXQogICAgcmV0dXJuIHJlcwoKZGVmIG1haW4oKTogIyN1c2FnZQogICAgdGVybXNyYz1pbnB1dCgpCiAgICBsaXN0dXJscz1wcmVwYXJhdXJsKHRlcm1zcmMpCiAgICBsLGksdD1nbG9iYWxzZWFyY2gobGlzdHVybHMpCgogICAgI3ByaW50KGdsb2JhbGxpc3QodCxsKSkKICAgIG5ld19sPVtdCiAgICBmb3IgbGluayBpbiBsOgogICAgICAgIHRlc3Q9ZnJhbWVzY3JhcC5zZnJhbWVzdHJpbmcobGluaykKICAgICAgICBpZiBsZW4obGluayk+MDogbmV3X2wuYXBwZW5kKHRlc3QpCiAgICBwcmludChuZXdfbCkKICAgIGlucHV0KCkKICAgIAppZiBfX25hbWVfXyA9PSAnX19tYWluX18nOgogICAgbWFpbigp