Загрузка...

How to store most code in pastebin?

Thread in C# created by encoder_devka Dec 10, 2023. 154 views

  1. encoder_devka
    encoder_devka Topic starter Dec 10, 2023 24 Aug 30, 2022
    Имеется код и я хочу чтобы он хранил в себе часть или даже полностью мой код.

    К примеру нужно чтобы данный код с заметками:

    CSHARP
    using System;
    using System.IO;

    class Program
    {
    static void Main()
    {
    Console.WriteLine("Welcome to the Console Note Taker!");
    while (true)
    {
    Console.WriteLine("\nChoose an option:");
    Console.WriteLine("1. Add a Note");
    Console.WriteLine("2. View Notes");
    Console.WriteLine("3. Exit");

    string choice = Console.ReadLine();

    switch (choice)
    {
    case "1":
    Console.Write("Enter your note: ");
    string note = Console.ReadLine();
    AddNoteToFile(note);
    Console.WriteLine("Note added successfully!");
    break;

    case "2":
    Console.WriteLine("Your Notes:");
    ViewNotes();
    break;

    case "3":
    Console.WriteLine("Exiting the program. Goodbye!");
    return;

    default:
    Console.WriteLine("Invalid option. Please try again.");
    break;
    }
    }
    }

    static void AddNoteToFile(string note)
    {
    string filePath = "notes.txt";
    File.AppendAllText(filePath, $"{note}{Environment.NewLine}");
    }

    static void ViewNotes()
    {
    string filePath = "notes.txt";
    if (File.Exists(filePath))
    {
    string[] notes = File.ReadAllLines(filePath);
    foreach (var n in notes)
    {
    Console.WriteLine($"- {n}");
    }
    }
    else
    {
    Console.WriteLine("No notes found.");
    }
    }
    }

    Нужно что бы весь код делающий исполнение хранился на пасте (txt файл с заметками на пк) как нужно реализовать код на пастебине и в мейне проекта
     
  2. Киана
    Киана Dec 10, 2023 Реклама от Кианы - lolz.live/threads/7756293/
    Что мешает на гитхаб залить?
     
    1. encoder_devka Topic starter
      Киана, как?)) я вообще не имею понятия как это сделать
    2. encoder_devka Topic starter
      Киана, типо смотри, у меня следующая задумка. свой локал форумчик со статьями xD . будут статьи залитые на пастебин и основной код тоже на пасте куда я буду давать ссылки на пасты со статьями для вывода итога. тоесть для вывода статьи.
    3. View the next comments (3)
  3. ChatGPT
    ChatGPT Dec 10, 2023 2250 Mar 14, 2023
    encoder_devka, чтобы хранить код на Pastebin, тебе потребуется использовать API Pastebin. Вот пример кода на C#, который отправляет код на Pastebin и возвращает ссылку на сохраненный код:

    CSHARP

    using System;
    using System.Net;
    using System.Text;

    class Program
    {
    static void Main()
    {
    string code = @"
    using System;
    using System.IO;

    class Program
    {
    static void Main()
    {
    Console.WriteLine(""Welcome to the Console Note Taker!"");
    while (true)
    {
    Console.WriteLine(""\nChoose an option:"");
    Console.WriteLine(""1. Add a Note"");
    Console.WriteLine(""2. View Notes"");
    Console.WriteLine(""3. Exit"");

    string choice = Console.ReadLine();

    switch (choice)
    {
    case ""1"":
    Console.Write(""Enter your note: "");
    string note = Console.ReadLine();
    AddNoteToFile(note);
    Console.WriteLine(""Note added successfully!"");
    break;

    case ""2"":
    Console.WriteLine(""Your Notes:"");
    ViewNotes();
    break;

    case ""3"":
    Console.WriteLine(""Exiting the program. Goodbye!"");
    return;

    default:
    Console.WriteLine(""Invalid option. Please try again."");
    break;
    }
    }
    }

    static void AddNoteToFile(string note)
    {
    string filePath = ""notes.txt"";
    File.AppendAllText(filePath, $""{note}{Environment.NewLine}"");
    }

    static void ViewNotes()
    {
    string filePath = ""notes.txt"";
    if (File.Exists(filePath))
    {
    string[] notes = File.ReadAllLines(filePath);
    foreach (var n in notes)
    {
    Console.WriteLine($""- {n}"");
    }
    }
    else
    {
    Console.WriteLine(""No notes found."");
    }
    }
    }";

    string apiKey = "YOUR_PASTEBIN_API_KEY";
    string pasteName = "My Code";
    string pasteFormat = "csharp";

    string url = "https://pastebin.com/api/api_post.php";
    string postData = $"api_dev_key={apiKey}&api_option=paste&api_paste_name={Uri.EscapeDataString(pasteName)}&api_paste_code={Uri.EscapeDataString(code)}&api_paste_format={pasteFormat}";

    using (WebClient client = new WebClient())
    {
    client.Encoding = Encoding.UTF8;
    string response = client.UploadString(url, postData);
    Console.WriteLine("Code uploaded successfully!");
    Console.WriteLine("Pastebin URL: " + response);
    }
    }
    }
    В этом примере код сохраняется в переменной `code`. Ты должен заменить `YOUR_PASTEBIN_API_KEY` на свой ключ API Pastebin. После выполнения кода, он загружает код на Pastebin и выводит ссылку на сохраненный код.

    Убедись, что у тебя установлен пакет `System.Net.Http` для работы с `WebClient`.
     
    1. encoder_devka Topic starter
      ChatGPT, не, ты не такой умный как думаешь =) ну или я тупой чтобы понять, но у тебя не решение , попробуй чтото другое придумать ))
    2. ChatGPT
      encoder_devka, извини, если мое предыдущее решение не подошло. Вот еще один способ сохранить код на Pastebin с использованием библиотеки `RestSharp`:

      CSHARP

      using System;
      using RestSharp;

      class Program
      {
      static void Main()
      {
      string code = @"
      using System;
      using System.IO;

      class Program
      {
      static void Main()
      {
      Console.WriteLine(""Welcome to the Console Note Taker!"");
      while (true)
      {
      Console.WriteLine(""\nChoose an option:"");
      Console.WriteLine(""1. Add a Note"");
      Console.WriteLine(""2. View Notes"");
      Console.WriteLine(""3. Exit"");

      string choice = Console.ReadLine();

      switch (choice)
      {
      case ""1"":
      Console.Write(""Enter your note: "");
      string note = Console.ReadLine();
      AddNoteToFile(note);
      Console.WriteLine(""Note added successfully!"");
      break;

      case ""2"":
      Console.WriteLine(""Your Notes:"");
      ViewNotes();
      break;

      case ""3"":
      Console.WriteLine(""Exiting the program. Goodbye!"");
      return;

      default:
      Console.WriteLine(""Invalid option. Please try again."");
      break;
      }
      }
      }

      static void AddNoteToFile(string note)
      {
      string filePath = ""notes.txt"";
      File.AppendAllText(filePath, $""{note}{Environment.NewLine}"");
      }

      static void ViewNotes()
      {
      string filePath = ""notes.txt"";
      if (File.Exists(filePath))
      {
      string[] notes = File.ReadAllLines(filePath);
      foreach (var n in notes)
      {
      Console.WriteLine($""- {n}"");
      }
      }
      else
      {
      Console.WriteLine(""No notes found."");
      }
      }
      }";

      string apiKey = "YOUR_PASTEBIN_API_KEY";
      string pasteName = "My Code";
      string pasteFormat = "csharp";

      var client = new RestClient("https://pastebin.com/api/api_post.php");
      var request = new RestRequest(Method.POST);
      request.AddParameter("api_dev_key", apiKey);
      request.AddParameter("api_option", "paste");
      request.AddParameter("api_paste_name", pasteName);
      request.AddParameter("api_paste_code", code);
      request.AddParameter("api_paste_format", pasteFormat);

      IRestResponse response = client.Execute(request);
      if (response.IsSuccessful)
      {
      Console.WriteLine("Code uploaded successfully!");
      Console.WriteLine("Pastebin URL: " + response.Content);
      }
      else
      {
      Console.WriteLine("Failed to upload code to Pastebin.");
      }
      }
      }
      В этом примере также используется переменная `code`, в которой хранится код. Замени `YOUR_PASTEBIN_API_KEY` на свой ключ API Pastebin. После выполнения кода, он загружает код на Pastebin и выводит ссылку на сохраненный код.

      Убедись, что у тебя установлен пакет `RestSharp` для работы с `RestClient`.
Loading...
Top