r/Python • • Mar 27 '18

Instagram in Terminal

2.0k Upvotes

97 comments sorted by

34

u/Shubbler Mar 27 '18

Incredible project, not too sure how to authenticate when Instagram's 2FA is on.

I know Reddit lets you sign in with <password>:<2FA code>, but can't seem to find anything similar for Instagram :(

18

u/ghostreport Mar 27 '18

I going to have to think about the 2FA part. Not an easy task.

11

u/Cabbage-Guy Mar 27 '18 edited Mar 27 '18

Hey OP, I was messing with 2FA and came up with the following solution,I know a pull request would have been better but I couldn't test the code as I am hitting the rate limit pretty quickly and Instagram is blocking me,So I thought of posting it here.Hopefully this helps :)

if res_text["two_factor_required"] == True:
    identifier = res_text["two_factor_info"]["two_factor_identifier"]
    username = credential["username"]
    verification_code = input("2FA Verification Code: ")
    verification_data = {"username":username,"verificationCode":verification_code,"identifier":identifier}
    two_factor_request = session.post("https://www.instagram.com/accounts/login/ajax/two_factor/", data=verification_data, allow_redirects=True)
    two_factor_text = json.loads(two_factor_request.text)
    if two_factor_text["status"] == "fail":
        return None,two_factor_text
    else:
        return session, res_text

Also you should probably use Host and User-Agent Headers for login

Edit: Change two_factor_request to two_factor_text

2

u/ghostreport Mar 27 '18

Holy shit! You so good bro!

2

u/Cabbage-Guy Mar 27 '18

Cheers! Also let me know if it works and if you face any errors.

1

u/Zorbithia Mar 29 '18

You win second prize thread MVP. Sweet work.

4

u/dvidsilva Mar 27 '18

Do they have app specific passwords?

1

u/13steinj Mar 27 '18

Github lets you use an api access key instead of your password for git logins. Does instagram have some option to get one?

1

u/ghostreport Mar 27 '18

Not really sure. Would have to look through the documentation.

1

u/[deleted] Jun 12 '18

I dont think so. They hate api access and external apps

26

u/deadwisdom greenlet revolution Mar 27 '18

You're hired.

6

u/ghostreport Mar 27 '18

Bro Thanks! lol

12

u/deadwisdom greenlet revolution Mar 27 '18

No, seriously if you want any contract work, and know anything about backend web development, hit me up.

21

u/[deleted] Mar 27 '18

It's beautiful.

2

u/ghostreport Mar 27 '18

Appreciated!

2

u/Ph0X Mar 27 '18

Now add terminal colors.

14

u/Boutmayun Mar 27 '18

Holy fuckin shit

4

u/ghostreport Mar 27 '18

No shit bro!

8

u/ThanatopsisJSH Mar 27 '18

This may not be the instagram we need but it is the instagram we deserve...

Next steps: Can I also get this for youtube?

2

u/ghostreport Mar 27 '18

I think youtube is already implemented. I remembered seeing it somewhere on GitHub.

1

u/[deleted] Jun 12 '18

Indeed, /u/ghostreport :

https://github.com/mps-youtube/mps-youtube

sudo apt-get install mps-youtube

198

u/colorlace Mar 27 '18

This is exactly what I've been looking for.

11

u/[deleted] Mar 27 '18

Lol what?

17

u/[deleted] Mar 28 '18

This is exactly what I've been looking for.

Where's areyoudeaf bot when you need it.

9

u/creativeMan Mar 27 '18

Bro. Terminology. tycat. Sixel. There are ways to have images rendered in a terminal.

More importantly, it's brilliant that you used an iPhone user agent to get the JSON. Good stuff.

9

u/[deleted] Mar 27 '18

There are ways to have images rendered in a few specific terminal emulators

4

u/roughreward Mar 27 '18

Reminds me of using Veronica / gopher. Simpler times my friends.

1

u/senorgorxme Mar 27 '18

Can someone guide me through the steps in order to get this running on macOS Sierra? I'm currently learning C++ but this looks like it could be a fun little project before taking (Python) next semester.

1

u/ghostreport Mar 27 '18

Do you have python installed on your mac? If no, do brew install python3 or google how to install python3. After you have python3 installed go to my github and follow the step.😄

1

u/senorgorxme Mar 28 '18

Downloaded both python3 and Atom to run the script but no luck :( Should I try running the start.py file in Terminal? Any suggestions are much appreciated!

1

u/ghostreport Mar 28 '18

I am not familiar with Atom. I use Vim + terminal, so maybe trying to run the script directly from the terminal?

1

u/Zorbithia Mar 29 '18

Did you install python in MacOS? Not intending to be annoyingly technical on the issue of semantics, but you said you downloaded, from what I recall, High Sierra (10.13) comes with Python 2.7 pre-installed automatically, so you'd have to update it if you go that route. Pretty simple to find a guide online for that.

1

u/DigitalOSH Mar 27 '18

Your terminal displays emoji?

1

u/ghostreport Mar 28 '18

Mac iterm2 : )

2

u/breakdownvoltage1 Mar 27 '18

The images on terminal reminds me of the DES image encryption...and why 3DES

2

u/Petrarch1603 Mar 27 '18

Instagram has a very difficult process for getting an API key

1

u/[deleted] Jun 12 '18

Las thing I heard is that for regular users they basically have no api access at all

From what I've read this restricting the API happened after Facebook bought them

2

u/killercap88 Mar 27 '18

Out of the loop: Can someone explain to me why this is wow?

1

u/inherently_silly Mar 27 '18

wow, this is bad ass!

1

u/no0bmustdie Mar 27 '18

Amazeballs

1

u/3xpert3 Mar 27 '18

Looks good

1

u/[deleted] Mar 27 '18

Awesome shits!

1

u/[deleted] Mar 27 '18

you're a weirdo, but i like it.

1

u/[deleted] Mar 27 '18

Strikingly simple. Can you explain shortly what exactly you are doing with the images to parse them to chars?

1

u/[deleted] Mar 27 '18

This is so cool you should integrate https://dereenigne.org/linux/vlc-caca-ascii-output/ next!

1

u/Rizzey Mar 27 '18

This is cyberpunk as fuck and I love it

1

u/[deleted] Mar 27 '18

I’m making an Instagram just for this

1

u/[deleted] Mar 27 '18

I love when it’s something so random, yet something so well done. It’s a neat way to learn - kudos!

1

u/fosiacat Mar 28 '18

mother of god

1

u/lector13 Mar 28 '18

very easy, but funny)

1

u/ericonr Mar 30 '18

Hmmm I tried to run it but got "checkpoint_required" printed to the console and it exited. Any ideas?

1

u/[deleted] Mar 31 '18

This is goddamn amazing.

1

u/nikkkhil Mar 27 '18

Amazing, I was looking to do a similar project

1

u/THE_ReD_TrucK Mar 27 '18

looks better than the website

-14

u/daniel Mar 27 '18

You should pick a better password than just an empty one.

5

u/pyryoer Mar 27 '18

You must be new!

5

u/Skydronaut Mar 27 '18

Definitely not new... the man's username is just... daniel

5

u/[deleted] Mar 27 '18

More importantly, that's an admin

0

u/[deleted] Mar 27 '18

[deleted]

3

u/daniel Mar 27 '18

Well it's less sarcasm and more dumb joke. I'll take the downvotes as a badge of honor.

0

u/TotesMessenger Mar 27 '18

I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

 If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)

-7

u/TheWildKernelTrick Mar 27 '18

Cmon man...

pipenv run python3 start.py

This is super sick by the way. Amazingly creative idea!

1

u/izxle Mar 27 '18

What does this do?

3

u/MrRaviex Mar 27 '18

You should check out the pipenv docs. pipenv runwill run the command in the virtual environment. I don't know why the comment is down voted.

5

u/[deleted] Mar 27 '18

[removed] — view removed comment

1

u/MrRaviex Mar 28 '18

Thanks, that makes sense :)

-27

u/[deleted] Mar 27 '18

why on earth you want to see your photo (which is mainly RGB) in terminal(binary) ???

32

u/logs28 Mar 27 '18

Why not?

-5

u/solaceinsleep Mar 27 '18

Gimmick at best but hey whatever floats your boat

4

u/logs28 Mar 27 '18

Not everything has to be functional. Even programmers can do things for fun

10

u/[deleted] Mar 27 '18

It looks like a fun coding project to me, absolutely no real-world use but probably interesting to make.

0

u/[deleted] Mar 27 '18

[deleted]

50

u/Artemis-Higgs Mar 27 '18

Have you considered adding a sixel option? It's another option for displaying images in a terminal :)

9

u/ghostreport Mar 27 '18

Thanks for the suggestion. I will try to integrate that when I get time!!

30

u/annodomini Mar 27 '18

You could instead us Unicode block characters along with truecolor to render a full color, low resolution version in a way that's compatible with a lot more terminals, though you have to have a font that has good support and a terminal that doesn't introduce any extra spacing.

5

u/pzl Mar 27 '18

that's amazing, but not great terminal support

16

u/TheWildKernelTrick Mar 27 '18

Starred! Badass project my friend!

9

u/theotherplanet Mar 27 '18

Just curious, what motivated you to undertake this project?

6

u/ghostreport Mar 27 '18

Just pure fun. Just wanted to play around with Instagram.

5

u/i_ate_god Mar 27 '18

now for full color ansi so it's like... Instagram BBS

3

u/lugatsby Mar 27 '18

I see you’re using the old API, the current docs don’t mention the feed endpoint anymore. How’d you get around this?

4

u/ghostreport Mar 27 '18

I poked around to see what response Instagram would give me and referenced a few other repositories.

0

u/[deleted] Mar 27 '18

[deleted]

1

u/ghostreport Mar 27 '18

Thanks for the suggestion. Will take a look at it when I get time : )

3

u/fuzzyinterval Mar 27 '18

But where's the fun in that, when you can ascii-ize the images?

0

u/[deleted] Mar 27 '18

[deleted]

42

u/Sacker12345 Mar 27 '18

Better than Snapchat.

9

u/ghostreport Mar 27 '18

This made me laugh so hard.

0

u/[deleted] Mar 27 '18

[deleted]

1

u/ghostreport Mar 27 '18

Just learn from the basics and if you keep up the work, you will eventually get there. I am still learning on a daily basis. Programming is fun because there is always something new everyday.

3

u/earthboundkid Mar 27 '18

It’s mostly about learning how to build and use reusable pieces so that you yourself don’t have to do everything alone. So for example, Instagram has an “API” which just means you can access its data over the web’s HTTP protocol. That’s great because it means you don’t have to figure out how to talk to Instagram from scratch but you can just import a standard web library to talk to it. Ditto for opening the images. Since they’re all normal JPEG files you can use a normal JPEG library. I would say 75% of being a professional developer is learning to use someone else’s tools and 25% is learning to write your own.

0

u/[deleted] Mar 27 '18

[deleted]

1

u/ghostreport Mar 28 '18

I believe there exists an extension that does this but haven't really dig into it yet.

0

u/[deleted] Mar 27 '18

[deleted]

1

u/theotherplanet Mar 27 '18

Lol I don't either

1

u/BringTheNipple Mar 27 '18

That isn't something you should alias easily. If some tools in your operating system expect python to point to the python2 executable they might stop working.