Merge pull request #40 from aphexcx/aphexcx/files_from_dir_and_api_token_input
Accept dirs as well as single files on command line, and also accept api_token via input if scraping it fails.
This commit is contained in:
commit
55bc410833
|
@ -85,6 +85,7 @@
|
|||
},
|
||||
"lxml": {
|
||||
"hashes": [
|
||||
"sha256:fa071559f14bd1e92077b1b5f6c22cf09756c6de7139370249eb372854ce51e6",
|
||||
"sha256:0a103253a94cdad86028d273aaebb8b30c75fdf009c23e52cdc8ce88429fd326",
|
||||
"sha256:10399bececdb67f0d9251ecf2dda2abf6ddeee6096741754356f1a3715c8c830",
|
||||
"sha256:12e348eb57fb79ccf91a49b7b937c49a5bbe1d73ba75589674b76a56d064bda0",
|
||||
|
@ -115,7 +116,7 @@
|
|||
"sha256:feb2144c2ae4035ad57165dd22bdc93b1389158a985c0497a096d39e2b2cd67b"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==4.1.0"
|
||||
"version": "==4.5.0"
|
||||
},
|
||||
"multidict": {
|
||||
"hashes": [
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
beautifulsoup4>=4.4, <5.0
|
||||
requests>=2.5.3, <3.0
|
||||
lxml==3.7.3
|
||||
lxml==4.5.0
|
||||
aiohttp==2.3.1
|
||||
idna-ssl==1.1.0
|
||||
|
|
24
upload.py
24
upload.py
|
@ -26,9 +26,11 @@ URL_LIST = "https://{team_name}.slack.com/api/emoji.adminList"
|
|||
API_TOKEN_REGEX = r'.*(?:\"?api_token\"?):\s*\"([^"]+)\".*'
|
||||
API_TOKEN_PATTERN = re.compile(API_TOKEN_REGEX)
|
||||
|
||||
|
||||
class ParseError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def _session(args):
|
||||
assert args.cookie, "Cookie required"
|
||||
assert args.team_name, "Team name required"
|
||||
|
@ -59,13 +61,13 @@ def _argparse():
|
|||
'--prefix', '-p',
|
||||
default=os.getenv('EMOJI_NAME_PREFIX', ''),
|
||||
help='Prefix to add to genereted emoji name. '
|
||||
'Defaults to the $EMOJI_NAME_PREFIX environment variable.'
|
||||
'Defaults to the $EMOJI_NAME_PREFIX environment variable.'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--suffix', '-s',
|
||||
default=os.getenv('EMOJI_NAME_SUFFIX', ''),
|
||||
help='Suffix to add to generated emoji name. '
|
||||
'Defaults to the $EMOJI_NAME_SUFFIX environment variable.'
|
||||
'Defaults to the $EMOJI_NAME_SUFFIX environment variable.'
|
||||
)
|
||||
parser.add_argument(
|
||||
'slackmoji_files',
|
||||
|
@ -103,7 +105,10 @@ def _fetch_api_token(session):
|
|||
|
||||
return match_group.group(1)
|
||||
|
||||
raise ParseError("No api_token found in page")
|
||||
print("No api_token found in page. Search your https://<teamname>.slack.com/customize/emoji "
|
||||
"page source for \"api_token\" and enter its value manually.")
|
||||
return raw_input(
|
||||
'Please enter the api_token ("xoxs-12345-abcdefg....") from the page: ').strip()
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -112,7 +117,10 @@ def main():
|
|||
existing_emojis = get_current_emoji_list(session)
|
||||
uploaded = 0
|
||||
skipped = 0
|
||||
for filename in args.slackmoji_files:
|
||||
|
||||
def process_file(filename):
|
||||
nonlocal skipped
|
||||
nonlocal uploaded
|
||||
print("Processing {}.".format(filename))
|
||||
emoji_name = '{}{}{}'.format(
|
||||
args.prefix.strip(),
|
||||
|
@ -126,6 +134,14 @@ def main():
|
|||
upload_emoji(session, emoji_name, filename)
|
||||
print("{} upload complete.".format(filename))
|
||||
uploaded += 1
|
||||
|
||||
for slackmoji_file in args.slackmoji_files:
|
||||
if os.path.isdir(slackmoji_file):
|
||||
for file in os.listdir(slackmoji_file):
|
||||
filename = os.path.join(slackmoji_file, file)
|
||||
process_file(filename)
|
||||
else:
|
||||
process_file(slackmoji_file)
|
||||
print('\nUploaded {} emojis. ({} already existed)'.format(uploaded, skipped))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue