r/badcode • • Nov 09 '20

[deleted by user]

[removed]

132 Upvotes

31 comments sorted by

View all comments

20

u/carfniex Nov 09 '20 edited Nov 10 '20

doesn't work too well right now but once we get more answers we'll be great. expects that the other answers take a filename

#!/bin/bash

curl --user-agent ua https://old.reddit.com/r/badcode/comments/jqv3dn/bad_code_coding_challenge_49_image_from_string_of/ -o page.html
i=1
while [ true ]; do
	xmllint --html --xpath '//div[contains(@class, "thing")]['${i}']//div[contains(@class, "usertext-body")]/div/pre/code/text()' page.html  2> /dev/null \
	| perl -MHTML::Entities -pe 'decode_entities($_);' > code${i}.sh
	if [[ $? -eq 0 ]]; then
		/bin/bash code${i}.sh $1
		if [[ $? -eq 0 ]]; then
			exit 0;
		fi
		mv code${i}.sh code${i}.py
		python code${i}.py $1
		if [[ $? -eq 0 ]]; then
			exit 0;
		fi
		python3 code${i}.py $1
		if [[ $? -eq 0 ]]; then
			exit 0;
		fi
	else 
		exit 420;
	fi
	i=$((i+1))
done

exit 69

3

u/Mabi19_ Nov 10 '20

This answer is so creative. I never would've thought of runtime-plagiarizing others' answers. Wow.