GithubHelp home page GithubHelp logo

baboleevan / curlconverter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from curlconverter/curlconverter

0.0 1.0 0.0 719 KB

convert curl commands to Python, JavaScript, PHP, R, Go, Rust, Dart, JSON, Ansible, Elixir

Home Page: https://curl.trillworks.com

License: MIT License

JavaScript 44.08% Python 10.10% PHP 1.95% Shell 0.06% R 8.42% Go 2.84% Rust 1.58% Dart 5.36% Elixir 9.72% MATLAB 15.91%

curlconverter's Introduction

NPM versionBuild Status

Convert cURL syntax to native Python, Go, PHP, JavaScript, R, Elixir and Dart HTTP code

Live Demo

https://curl.trillworks.com

Install

$ npm install --save curlconverter

Usage

var curlconverter = require('curlconverter');

curlconverter.toPython("curl 'http://en.wikipedia.org/' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://www.wikipedia.org/' -H 'Cookie: GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14' -H 'Connection: keep-alive' --compressed");

Returns a string of Python code like:

import requests

cookies = {
    'GeoIP': 'US:Albuquerque:35.1241:-106.7675:v4',
    'uls-previous-languages': '%5B%22en%22%5D',
    'mediaWiki.user.sessionId': 'VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y',
    'centralnotice_buckets_by_campaign': '%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D',
    'centralnotice_bannercount_fr12': '22',
    'centralnotice_bannercount_fr12-wait': '14',
}

headers = {
    'Accept-Encoding': 'gzip, deflate, sdch',
    'Accept-Language': 'en-US,en;q=0.8',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Referer': 'http://www.wikipedia.org/',
    'Connection': 'keep-alive',
}

response = requests.get('http://en.wikipedia.org/', headers=headers, cookies=cookies)

Contributing

I'd rather write programs to write programs than write programs.

Dick Sites, Digital Equipment Corporation, September 1985

Make sure you're running node 12 or greater. The test suite will fail on older versions of node.

If you add a new generator, make sure to update the list of supported languages in cli.js or else it won't be accessible from the command line. Further, you'll want to update test.js and index.js for your new generator to make it part of the testing.

If you want to add new functionality, start with a test.

  • Create a file containing the curl command in fixtures/curl_commands with a descriptive filename like post_with_headers.txt
  • Create a file containing the output in fixtures/python_output/ with a matching filename (but different extension) like post_with_headers.py
  • Run tests with npm test.
  • If your filenames match correctly, you should see one failing test. Fix it by modifying the parser in util.js or the generators in generators/

The parser generates a generic data structure consumed by code generator functions.

You can run a specific test with this command:

node test.js --test=test_name

where "test_name" is a file (without extension) in fixtures/curl_commands

You can run a specific test with this command:

node test.js --language=R

I recommend setting this up with a debugger so you can see exactly what the parser is passing to the generator. Here's my Intellij run configuration for a single test: Screenshot of intellij debug configuration

Before submitting a PR, please check that your JS code conforms to the code style enforced by standardjs. Use the following to fix your code if it doesn't:

$ standard --fix my_file.js

If you get stuck, please reach out via email. I am always willing to hop on a google hangout and pair program.

Contributors

  • Muhammad Reza Irvanda (python env vars)
  • Weslen Nascimento (Node fetch)
  • Roman Druzki (Backlog scrubbing, parsing improvements)
  • NoahCardoza (Command line interface)
  • ssi-anik (JSON support)
  • hrbrmstr (R support)
  • daniellockard (Go support)
  • eliask (improve python output)
  • trdarr (devops and code style)
  • nashe (fix PHP output)
  • bfontaine (reduce code duplication in test suite)
  • seadog007
  • nicktimko
  • wkalt
  • nico202
  • r3m0t
  • csells (Dart support)
  • yanshiyason (Elixir support)
  • Robertof (Rust enhancements, correctness, es6)
  • clintonc (Code quality / brevity, test suite consistency)
  • MarkReeder (JSON formatting)
  • cf512 (bugfixes and feature requests)
  • DainisGorbunovs (MATLAB support)
  • TennyZhuang (data-raw support)

License

MIT © Nick Carneiro

curlconverter's People

Contributors

nickcarneiro avatar csells avatar cf512 avatar jgroom33 avatar robertof avatar clintonc avatar eliask avatar romadrutskii avatar dainisgorbunovs avatar jay9596 avatar ssi-anik avatar trdarr avatar yanshiyason avatar dependabot[bot] avatar markreeder avatar seadog007 avatar bfontaine avatar daniellockard avatar recuencojones avatar muzavan avatar nico202 avatar noahcardoza avatar codenoid avatar r3m0t avatar wkalt avatar hrbrmstr avatar tennyzhuang avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.