Created
January 17, 2017 09:34
-
-
Save chamoda/443742484d9e0682ee6ca55e96c86478 to your computer and use it in GitHub Desktop.
Autogenerate android butterknife binding code from xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
# | |
# Chamoda Panthage | |
# chamodac@gmail.com | |
# | |
import fileinput | |
from bs4 import BeautifulSoup | |
xml = '' | |
for line in fileinput.input(): | |
xml += line | |
soup = BeautifulSoup(xml, 'xml') | |
elements = soup.find_all(lambda tag: 'android:id' in tag.attrs) | |
print('\n') | |
for element in elements: | |
print '@BindView(R.id.' + element['android:id'].split("/")[1] + ') ' + element.name + ' ' + element['android:id'].split("/")[1] + ';' | |
print('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment